在PHP的非靜態方法中可以呼叫靜態方法
class test{ public static function strPrint(){ echo 'this is strPrint static function<br>'; } public function staticFuncInvoke(){ self::strPrint(); } } $test = new test(); $test->staticFuncInvoke();
上面的程式碼會輸出: this is strPrint static function.
而下面的程式碼會直接給出
Fatal error: Using $this when not in object context in E:htdocstestcontent.php on line 6class test{ public static function strPrint(){ $this->staticFuncInvoke(); } public function staticFuncInvoke(){ echo 'this is a nonstatic function named staticFuncInvoke'; } } test::strPrint();