Home >Backend Development >PHP Tutorial >Detailed description of php static binding
This article briefly describes static binding in PHP. Students who are not familiar with static binding in PHP can take a look at this article about static binding in PHP!
Late static bindingThe working principle is to store the class name in the previous "non-forwarding call" (non-forwarding call
).
When making a static method call, the class name is the one explicitly specified (usually on the left side of the :: operator );
When a non-static method call is made, it is the class to which the object belongs.
The so-called "forwarding call" (forwarding call
) refers to the static call made in the following ways: self::
, parent::
, static::
and forward_static_call()
. You can use the get_called_class()
function to get the class name of the called method, and static::
points out its scope.
Use self:: or CLASS a static reference to the current class , depending on how the current method is defined Category:
Example:
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 ();
Result:
// A
The above describes all the contents of this article. Everyone must feel confused after reading it. I hope You can read more with examples and implement two of them yourself!
related suggestion:
PHP Late Static Binding Example Sharing
PHP Post OOP Post Static Binding
The above is the detailed content of Detailed description of php static binding. For more information, please follow other related articles on the PHP Chinese website!