In PHP, static methods can be called as if they were instance methods:
class A { public static function b() { echo "foo"; } } $a = new A; A::b();
Is there a way to determine inside b() whether the method was called statically or not?
I tried isset($this) , but in both cases it returns false, and debug_backtrace() shows that both calls are actually static calls
array(1) { [0]=> array(6) { ["file"]=> string(57) "test.php" ["line"]=> int(23) ["function"]=> string(1) "b" ["class"]=> string(1) "A" ["type"]=> string(2) "::" ["args"]=> array(0) { } } } Foo array(1) { [0]=> array(6) { ["file"]=> string(57) "test.php" ["line"]=> int(24) ["function"]=> string(1) "b" ["class"]=> string(1) "A" ["type"]=> string(2) "::" ["args"]=> array(0) { } } }
chriso
source share