php中以类名::方法调用非静态方法

php中静态公开方法static public可以在类外 类名::方法 调用

当没有static的public方法时,在某种条件下也可以采用此方式调用,虽然会报Strict Standards错误

这种条件是调用的这个方法中不能使用代表对象本身的$this

View Code
 1 <?php
 2 //error_reporting(0);
 3 class test {
 4     function tt() {
 5         echo 'tt';
 6     }
 7 
 8     function xx() {
 9         test::tt();
10         echo 'xx';
11     }
12 
13     function ss() {
14         $this->tt();
15         echo 'ss';
16     }
17 }
18 
19 $m = new test;
20 $m::ss(); //致命错误 Fatal error: Using $this when not in object context in XXX
21 test::xx(); //Strict Standards: Non-static method test::ss() should not be called statically in XXX
22 ?>

 

posted @ 2013-02-28 15:53  Caps  阅读(285)  评论(0编辑  收藏  举报