Search code examples
phpmethodsstatic

How do I check in PHP that I'm in a static context (or not)?


Is there any way I can check if a method is being called statically or on an instantiated object?


Solution

  • Try the following:

    class Foo {
       function bar() {
          $static = !(isset($this) && $this instanceof self);
       }
    }