【发布时间】:2014-07-17 05:34:58
【问题描述】:
什么时候 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
【问题讨论】:
-
最好使用
non static定义。
标签: php class dynamic static-methods