|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-11-23 22:35 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2014-11-23 22:35 UTC] requinix@php.net
[2014-11-23 23:03 UTC] llmll at gmx dot de
[2014-11-23 23:43 UTC] requinix@php.net
[2014-11-23 23:59 UTC] llmll at gmx dot de
[2014-11-24 00:51 UTC] requinix@php.net
[2014-11-24 07:29 UTC] llmll at gmx dot de
[2014-11-24 08:32 UTC] requinix@php.net
[2014-11-24 13:06 UTC] llmll at gmx dot de
[2014-11-24 23:42 UTC] requinix@php.net
-Block user comment: No
+Block user comment: Yes
[2014-11-24 23:42 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 21:00:01 2025 UTC |
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"