PHP: call to an instance method via ClassName::method syntax, results in a static call?

后端 未结 2 1129
暖寄归人
暖寄归人 2021-01-15 22:05

Her is my code:

class MyClass 
{
   public $prop;
   public function method ()
   {
     echo $this->prop;
   }
}

Then somewhere in the

2条回答
  •  迷失自我
    2021-01-15 22:38

    For legacy reasons, any class method could be called statically even if it wasn't declared static, because you previously couldn't declare them as such. In those cases, $this would simply refer to nothing because it's not an object-context variable.

    In PHP 5 you get an E_STRICT warning for calling non-static methods statically (as you just did).

提交回复
热议问题