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

后端 未结 11 1288
时光说笑
时光说笑 2020-11-30 08:16

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

11条回答
  •  醉梦人生
    2020-11-30 09:09

    Try the following:

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

    Source: seancoates.com via Google

提交回复
热议问题