php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32240 self:: syntax cannot be used transparently if used in inherited class functions
Submitted: 2005-03-09 01:17 UTC Modified: 2005-03-30 19:14 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: thenewparadigm at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-09 (dev) OS: Windows 98SE
Private report: No CVE-ID: None
 [2005-03-09 01:17 UTC] thenewparadigm at hotmail dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-30 19:14 UTC] tony2001@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #30934.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 10 18:00:02 2025 UTC