tags:

views:

54

answers:

1

Let's say I have a FooClass with a bar() method. Inside of the bar() method, is there any way to tell if it's being called statically or not, so I can treat these two cases differently?

FooClass::bar();
$baz = new FooClass();
$baz->bar();
+4  A: 
class FooClass {

    function bar() {
        if ( isset( $this ) ) {
            echo "not static";
        }
        else {
            echo "static";
        }
    }

}

FooClass::bar();
$baz = new FooClass();
$baz->bar();
Galen
Thats it, but wrap `$this` in `isset()` to not trigger any additional notice
dev-null-dweller