I saw several symbols related to PHP today. One is @, which is added in front of a variable to suppress the PHP interpreter from reporting errors, which means that even if an error occurs, it will not be displayed.
There is also a more important symbol PHP's range resolution operator (::)
It is useful to access functions in a class or functions and variables in a base class without declaring any instances. And the :: operator is used in this case.
Copy code The code is as follows:
class A {
function example() {
echo "I am the original function A::example().
n";
}
}
class B extends A {
function example() {
echo "I am the redefined function B::example().
n";
A::example();
}
}
// A The class has no objects, this will output
// I am the original function A::example().
A::example();
// Create a class B Object
$b = new B;
// This will output
// I am the redefined function B::example().
// I am the original function A::example().
$b->example();
?>
The above example calls a function of class A example(), but there is no object of class A here, so example() cannot be called using $a->example() or similar methods. Instead we call example() as a class function, that is, as a function of the class itself, rather than any object of this class.
There are class functions here, but no class variables. In fact, there is no object at all when the function is called. Thus a class function may not use any objects (but may use local or global variables), and may not use the $this variable at all.
In the above example, class B redefines the function example(). The function example() originally defined in class A will be masked and will no longer take effect unless the :: operator is used to access the example() function in class A. For example: A::example() (actually, it should be written as parent::example(), which is introduced in the next chapter).
For that matter, for the current object, it may have object variables. So you can use $this and object variables inside object functions.
http://www.bkjia.com/PHPjc/323907.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323907.htmlTechArticleI saw several symbols related to PHP today. One is @, which is added in front of a variable to suppress the PHP interpreter from reporting errors, which means that even if an error occurs, it will not be displayed. One more...