1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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.
而下面的代码会直接挂掉,php直接给出fatal error:
Fatal error: Using $this when not in object context in E:\htdocs\test\content.php on line 6
1
2
3
4
5
6
7
8
9
10
11
12
|
class test{ public static function strPrint(){ $this ->staticFuncInvoke(); } public function staticFuncInvoke(){ echo 'this is a nonstatic function named staticFuncInvoke' ; } } test::strPrint(); |
以上就是小编为大家带来的浅谈PHP中静态方法和非静态方法的相互调用全部内容了,希望大家多多支持服务器之家~