This article simply describes the static bindings in PHP, for the static bindings in PHP is not so familiar with the students can take a look at this article about the static binding of PHP Oh!
Late static binding works by storing the class name on the previous "non-forwarding call" ( non-forwarding call
).
When a static method call is made, the class name is the one explicitly specified (usually in the left part of the: operator);
When a non-static method call is made, the class to which the object belongs.
The so-called "forwarding Call" ( forwarding call
) refers to static calls made in the following ways: self::
, parent::
static::
as well forward_static_call()
. get_called_class()
a function is available to get the class name of the method being called, and static::
its scope is indicated.
Self:: the limit
Use self:: or a static reference to the current class, depending on the class in which the current method is defined:
Cases:
Class A {public static function who () { echo CLASS; } public static function test () {self :: Who (); }} Class B extends A {public static function who () { echo CLASS; }} B:: Test ();
Results:
A
Above all the content of this article, we have seen after must feel very confused, I hope you can combine examples to see and achieve their own two articles!
Related recommendations:
PHP late static binding instance sharing
PHP OOP post-term static binding