ID: 47620 Updated by: dmi...@php.net Reported By: olemarkus dot with at student-media dot no -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.3CVS-2009-03-11 (snap) -Assigned To: +Assigned To: dmitry New Comment:
It's hard to explain, but it's expected. In case the method getName() doesn't declared as "static" it's called dynamically with current $this (A). This feature is kept for ages for backward compatibility. You can even see "strict" warning: Strict Standards: Non-static method B::getName() should not be called statically, assuming $this from incompatible context in ... In case you declare getName() "static" you'll get that you expect. Previous Comments: ------------------------------------------------------------------------ [2009-03-11 14:05:59] j...@php.net And here is the code: <?php namespace A { class A { function __construct() { echo \C\C::getName() . "\n"; } } } namespace B { abstract class B { static protected $name = ''; function getName() { return static::$name; } } } namespace C { class C extends \B\B { static protected $name = 'C'; } } namespace { echo \C\C::getName() . "\n"; $a = new \A\A(); } ?> ------------------------------------------------------------------------ [2009-03-11 07:18:24] olemarkus dot with at student-media dot no Description: ------------ When using static:: in a parent class to refer to the child class that was called, the keyword is resolved to the caller class instead. Reproduce code: --------------- http://olemarkus.com/issue.txt Expected result: ---------------- I expect both calls to \C\C::getName() to yield the same result: C C Actual result: -------------- The second one gives the following output: C Fatal error: Access to undeclared static property: A\A::$name in issue.php on line 13 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47620&edit=1