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?
+6
A:
Admittedly not offhand...but Sean Coates has a cool and fairly simple approach to finding this out:
$isStatic = !(isset($this) && get_class($this) == __CLASS__);
Ben
2009-10-30 02:53:18
That did it, cheers!
Pekka
2009-10-30 03:59:25
+2
A:
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.
Amber
2009-10-30 02:54:59