Introduction to the Post-object static binding function of PHP, Introduction to Object-oriented function
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:
Copy the Code code 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/1000251.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000251.html techarticle PHP Post-object-oriented static binding function introduction, object-oriented features introduced in this article will be the late PHP static binding features, it is mainly used to solve the scope of inheritance in the reference static ...