PHP;">
class test{
public static function strPrint(){
echo 'this is strPrint static function
';
}
public function staticFuncInvoke(){
self::strPrint();
}
}
$test = new test();
$test->staticFuncInvoke();
上面的代码会输出: this is strPrint static function.
而下面的代码会直接挂掉,PHP直接给出fatal error:
Fatal error: Using $this when not in object context in E:\htdocs\test\content.PHP on line 6
public static function strPrint(){
$this->staticFuncInvoke();
}
原文链接:https://www.f2er.com/php/18883.html$this->staticFuncInvoke();
}
public function staticFuncInvoke(){
echo 'this is a nonstatic function named staticFuncInvoke';
}
}
test::strPrint();