Saturday, 17 August 2013

PHP 5.3 strange behaviour on static:: late binding

PHP 5.3 strange behaviour on static:: late binding

<?php
class base
{
public static function show($className=__CLASS__)
{
print_r($className);
}
public function test()
{
static::show();
}
}
class A extends base
{
public static function show($className=__CLASS__)
{
print_r($className);
}
}
class B
{
public function t()
{
A::test();
}
}
class C
{
public function t()
{
A::test(); <<<
}
}
B::t();
$c = new C;
$c->t();
?>
Output:
A
Fatal error: Call to undefined method C::show() in
/var/www/dashboard/test.php on line 12
Why did PHP try to find C::show() rather than A::show?

No comments:

Post a Comment