从什么时候 PHP 允许像动态函数一样调用静态函数了?
我使用的是 php 5.3.2
class weird{
public static function iamstatic($calledFrom){
echo "I am a static function called with a $calledFrom operator\n";
}
public function test(){
self::iamstatic("static");
$this->iamstatic("dynamic");
}
}
$c = new weird();
$c->test();
weird::iamstatic("Static outside class");
$c->iamstatic("Dynamic outside class");
输出:
I am a static function called with a static operator
I am a static function called with a dynamic operator
I am a static function called with a Static outside class operator
I am a static function called with a Dynamic outside class operator
最佳答案
php5.0及以上版本总是可以的。
此外,文档中提到了它 ( static )
Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static cannot be accessed with an instantiated class object (though a static method can).
这不是一个错误 ( static methods assigned to instances )
关于PHP静态函数在动态环境中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24795599/