Req #68593 [NEW]: Namespace not resolved at runtime like with static::

From: Date: Thu, 11 Dec 2014 22:07:27 +0000
Subject: Req #68593 [NEW]: Namespace not resolved at runtime like with static::
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189021@lists.php.net to get a copy of this message
From: llmll at gmx dot de Operating system: any PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Namespace not resolved at runtime like with static:: Description: ------------ The problem is equivalent to self:: and static:: but on the namespace realm. self:: resolves to the defining class while static:: resolves to the current instance class. Take a second to understand the test script and expected result. Reopening #68485 as current behaviour deviates clearly from the documentation, which the original maintainer failed to grasp. Test script: --------------- // original namespace namespace Alpha; class Helper { public static $Value = "ALPHA"; } class Caller { public static function Write() { // call to relative neighbour class Helper, resolves to \Alpha\Helper:: echo Helper::$Value; } } // now both classes are inherited into another namespace namespace Beta; class Helper extends \Alpha\Helper { public static $Value = 'BETA'; } class Caller extends \Alpha\Caller {} \Beta\Caller::Write(); Expected result: ---------------- This should print "BETA". PHP namespace resolution documentation states: Inside namespace (say A\B), calls to unqualified or qualified class names (not fully qualified class names) are resolved at >>> RUN-TIME <<<. This only makes sense, if at runtime the current class scope and the current namespace are taken into account to resolve the class. Otherwise resolving at runtime or at compiletime makes no difference. Actual result: -------------- The call to Helper::$Value is resolved at complie-time which is breaking inheritance logic. Helper:: should resolve to the instance namespace, because it is called without a namespace qualifier, meaning we want the relative class to the current namespace. Otherwise we could have written the fully-qualified \Alpha\Helper to fix the used Helper class, even in child classes. -- Edit bug report at https://bugs.php.net/bug.php?id=68593&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68593&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68593&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68593&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68593&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68593&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68593&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68593&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68593&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68593&r=support Expected behavior: https://bugs.php.net/fix.php?id=68593&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68593&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68593&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68593&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68593&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68593&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68593&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68593&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68593&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68593&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68593&r=mysqlcfg

« previous php.bugs (#189021) next »