开发者

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

开发者 https://www.devze.com 2022-12-10 15:19 出处:网络
Does anybody know offhand the way to tell whether I\'m being called statically (Clas开发者_开发百科sname::function) or inside an object ($classInstance->function) inside a PHP method?Admittedly not of

Does anybody know offhand the way to tell whether I'm being called statically (Clas开发者_开发百科sname::function) or inside an object ($classInstance->function) inside a PHP method?


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

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


Check if $this is set and equal to the class. It will be equal for an instance call and non-equal (or null) for a static call.

0

精彩评论

暂无评论...
验证码 换一张
取 消