Few people know, that PHP resolves $this to the the calling(!) object in static context.

The mind-boggling problems this raises in some situations, were somewhat attenuated with the introduction of the concept of static methods in PHP5.

But the underlying mechanism is unchanged even in PHP 5.3.3.

Try the following example and scratch your head.

[geshi lang=PHP]
error_reporting(E_ERROR);

class Playground extends PHPUnit_Framework_TestCase {
public function testFoo() {
$bar = new Bar();
$this->assertSame(‘Bar’, $bar->test());

}
}

class Foo {
public function test() {
return get_class($this);
}
}

class Bar {
public function test() {
return Foo::test();
}
}
[/geshi]