Take the 2-minute tour ×

Her is my code:

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

Then somewhere in the code, accidently:


I would expect to have an interpretation error about the above line, because the called method is not static. Instead, the method was called, and I received an exception about $prop not existing. So i understand that the method was called as a static method, even though it's not.

Does it work this way? (Why the hell? )

share|improve this question
Check your error reporting, they may just be hidden, look for your error_log near your main file. –  RobertPitt Jan 12 '11 at 1:21
add comment

2 Answers

up vote 4 down vote accepted

Calling non-static methods statically generates an E_STRICT level warning.


I suppose you have E_STRICT warnings suppressed. It works (likely for legacy reasons), but it's not recommended.

share|improve this answer
add comment

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).

share|improve this answer
add comment

Your Answer


