Is there any way I can check if a method is being called statically or on an instantiated object?
Test for $this:
class Foo {
function bar() {
if (isset($this)) {
echo "Y";
} else {
echo "N";
}
}
}
$f = new Foo();
$f->bar(); // prints "Y"
Foo::bar(); // prints "N"
Edit: As pygorex1 points out, you can also force the method to be evaluated statically:
class Foo {
static function bar() {
if (isset($this)) {
echo "Y";
} else {
echo "N";
}
}
}
$f = new Foo();
$f->bar(); // prints "N", not "Y"!
Foo::bar(); // prints "N"