Home > Article > Backend Development > PHP late static binding example sharing
1. The working principle of late static binding 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 making a non-static method call, it is the class to which the object belongs. This feature is named "late static binding" from a language-internal perspective. "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.
2. Test example:
class A{ public function run()
{ static::test(); //后期静态绑定
self::test(); //不是后期静态绑定 }
public static function test()
{ echo 'A Class<br>';
}}class B extends A
{ public static function test()
{ echo 'B Class<br>'; }}
$a = new B();$a->run();
//输出结果
//B Class
//A ClassRelated recommendations:
Detailed description of a late static binding in Laravel
PHP object-oriented post-static binding function introduction
The above is the detailed content of PHP late static binding example sharing. For more information, please follow other related articles on the PHP Chinese website!