How to tell whether I'm static or an object?

后端 未结 2 1799
春和景丽
春和景丽 2020-12-07 04:41

Does anybody know offhand the way to tell whether I\'m being called statically (Classname::function) or inside an object ($classInstance->function) inside a PHP method?

2条回答
  •  执笔经年
    2020-12-07 05:11

    Admittedly not offhand...but Sean Coates has a cool and fairly simple approach to finding this out:

    $isStatic = !(isset($this) && get_class($this) == __CLASS__);
    

提交回复
热议问题