I maintain an application that uses a (to me) surprising PHP quirk/bug/feature. Consider this code:
<?php
class Bar {
// called statically
public function doStuff() {
print_r($this);
}
}
class Foo {
public function main() {
Bar::doStuff();
}
}
$foo = new Foo();
$foo->main();
Running on PHP 5.2.x, the output is:
Foo Object ( )
That means, although Bar::doStuff() is called statically, it still has access to $this where $this is a reference to the object that called Bar::doStuff(). Never came across that behaviour until recently. Quite evil to rely on this in production code if you ask me.
If you add a static and change the method signature to public static function doStuff() it throws a E_NOTICE: Undefined variable: this - which seems right to me.
Anyone has an explanation for this behaviour?