Bug #68485 [NEW]: late namespace resolution with cross-namespace inheritance missing

From: Date: Sun, 23 Nov 2014 21:50:27 +0000
Subject: Bug #68485 [NEW]: late namespace resolution with cross-namespace inheritance missing
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188760@lists.php.net to get a copy of this message
From: llmll at gmx dot de Operating system: any PHP version: 5.5.19 Package: Class/Object related Bug Type: Bug Bug description:late namespace resolution with cross-namespace inheritance missing Description: ------------ Since PHP 5.3 we have late static binding to get a static variable from the actually instantiated class type instead of the declared type. This is an important feature, but it does not take into account a change in namespace. If the inheriting class lives in another namespace the wrong value is taken. If inside a namespace a class uses a peer class by its relative name, and later both classes are derived in another namespace, all accesses go to the original namespace where the class was declared in the first place. Neccessary would be a late (runtime) namespace resolution for class names, the same was it works for static:: Test script: --------------- <?php namespace Alpha; class Base { public static function Write() { echo Helper::$Value; } } class Helper { public static $Value = "ALPHA"; } namespace Beta; class Base extends \Alpha\Base { } class Helper extends \Alpha\Helper { public static $Value = 'BETA'; } \Beta\Base::Write(); ?> Expected result: ---------------- As the exmple calls \Beta\Base::Write() in \Beta namespace one would expect the output to be "BETA". The original static property is overwritten in Beta-namespace The calls Helper::$Value should be call-context-sensitive. If called in namespace \Alpha it shoult print "ALPHA" if called from a \Beta class, "BETA". Actual result: -------------- prints "ALPHA" -- Edit bug report at https://bugs.php.net/bug.php?id=68485&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68485&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68485&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68485&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68485&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68485&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68485&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68485&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68485&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68485&r=support Expected behavior: https://bugs.php.net/fix.php?id=68485&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68485&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68485&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68485&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68485&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68485&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68485&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68485&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68485&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68485&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68485&r=mysqlcfg

« previous php.bugs (#188760) next »