Introduction to the static binding function of PHP object-oriented post-phase
This article describes the post-static binding functionality of PHP, which is primarily used to resolve classes that refer to static calls within an inherited scope.
First look at the following example:
The code is as follows:
Class Person
{
public static function status ()
{
Self::getstatus ();
}
protected static function GetStatus ()
{
echo "person is alive";
}
}
Class deceased extends person
{
protected static function GetStatus ()
{
echo "person is deceased";
}
}
Deceased::status (); Person is alive
Obviously, the result is not what we expected, because self: depends on the class in which it was defined, not the class in which it was run. To solve this problem, you might override the status () method in the inheriting class, and a better solution would be to add post-static binding functionality after PHP 5.3.
Copy the code code as follows:
Class Person
{
public static function status ()
{
Static::getstatus ();
}
protected static function GetStatus ()
{
echo "person is alive";
}
}
Class deceased extends person
{
protected static function GetStatus ()
{
echo "person is deceased";
}
}
Deceased::status (); Person is deceased
Visible, Static:: Does not point to the class that is currently in, in fact, it is evaluated in the run, forcing all properties of the final class to be obtained.
Therefore, it is recommended that you do not use self again::, use static::
http://www.bkjia.com/PHPjc/1001667.html www.bkjia.com true http://www.bkjia.com/PHPjc/1001667.html techarticle PHP Post-object-oriented static binding feature This article describes the late-stage PHP static binding feature, which is primarily used to resolve classes that refer to static calls within an inherited scope. First of all, see ...