2011-01-12 78 views
1

可能重複:
PHP: call to an instance method via ClassName::method syntax, results in a static call ?!爲什麼可以這樣調用非靜態成員函數?

class A 
{ 
    function foo() 
    { 
     if (isset($this)) { 
      echo '$this is defined ('; 
      echo get_class($this); 
      echo ")\n"; 
     } else { 
      echo "\$this is not defined.\n"; 
     } 
    } 
} 

A::foo(); 

這是一個錯誤或功能?

+0

這是問剛纔:http://stackoverflow.com/questions/4664511/php-call-to-an-instance-method-via-classnamemethod-syntax-results-in-a-static – BoltClock 2011-01-12 03:53:06

回答

1

顯然這是允許的,但絕對不鼓勵。 According to the manual

調用非靜態方法會靜態生成E_STRICT級別警告。

+0

他問``這個' – zerkms 2011-01-12 03:53:51

相關問題