当你使用static :: NAME时,它是一个称为后期静态绑定(或LSB)的功能.有关此功能的更多信息,请访问LSB的php.net文档页面:http://nl2.php.net/manual/en/language.oop5.late-static-bindings.php
一个例子就是这个用例:
<?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();
?>
Run Code Online (Sandbox Code Playgroud)
这输出A,这并不总是令人满意的.现在替换self为static创建:
<?php
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
static::who(); // Here comes Late Static Bindings
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::test();
?>
Run Code Online (Sandbox Code Playgroud)
并且,正如您所料,它输出"B"