Look at an example first:
<code><?php 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(); ?></code>
Output:
<code>A </code>
If using late binding:
<code><?php class A { public static function who() { echo __CLASS__; } public static function test() { static::who(); // 后期静态绑定从这里开始 } } class B extends A { public static function who() { echo __CLASS__; } } B::test(); ?></code>
Output:
<code>B </code>
Use self:: or CLASS to make a static reference to the current class, depending on the class in which the current method is defined , rather than the class of the caller.
"Late binding" means that static:: is no longer resolved to the class in which the current method is defined, but is calculated at actual runtime. It can also be called "static binding" because it can be used for (but is not limited to) calls to static methods.
The above has introduced late binding in PHP, including static methods. I hope it will be helpful to friends who are interested in PHP tutorials.