|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-03-30 19:14 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 18:00:02 2025 UTC |
Description: ------------ Object oriented code utilizing the self:: syntax does not function transparently when a class calls one of its inherited methods given that self:: always refers to the class in which it is used, without regard to the context in which it is used. Classes are unable to use their own static methods and variables in any way when accessed through inherited methods or overridden methods called using the parent:: syntax without explicitly calling the class method or variable by using the class name with the :: operator; eg MyClass::desiredMethod(); This bug applies to all PHP 5.x.x builds thus far. I have confirmed the bug in both modified php.ini and php.ini-dist configurations using Apache 1.3.31. Reproduce code: --------------- class parentClass { public static function methodOne() { self::methodTwo(); } public static function methodTwo() { echo "methodTwo as defined in parentClass\n"; } } class childClass extends parentClass { public static function methodTwo() { echo "methodTwo as defined in childClass\n"; } } parentClass::methodOne(); childClass::methodOne(); Expected result: ---------------- The following output was expected: methodTwo as defined in parentClass methodTwo as defined in childClass I expected methodOne in the parentClass to call methodTwo as defined in the calling class, as would be done if using the -> operator with non-static methods. Actual result: -------------- The following output was generated by the code: methodTwo as defined in parentClass methodTwo as defined in parentClass At the moment, the only way to make the code work as expected is to define methodOne in childClass, purely identical to the one already found in parentClass.