Static methods can be called in non-static methods of PHP
class test{ public static function strPrint(){ echo 'this is strPrint static function<br>'; } public function staticFuncInvoke(){ self::strPrint(); } } $test = new test(); $test->staticFuncInvoke();
The above code will output: this is strPrint static function.
And the following code will hang directly, and PHP will directly give fatal error:
Fatal error: Using $this when not in object context in E:htdocstestcontent.php on line 6
class test{ public static function strPrint(){ $this->staticFuncInvoke(); } public function staticFuncInvoke(){ echo 'this is a nonstatic function named staticFuncInvoke'; } } test::strPrint();
The above is the editor’s brief discussion on the mutual calling of static methods and non-static methods in PHP That’s all. I hope everyone will support the PHP Chinese website~
For more articles on the mutual calling of static methods and non-static methods in PHP, please pay attention to the PHP Chinese website!