|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30235 Inheritance of private static variables fails (related to self:: )
Submitted: 2004-09-25 23:45 UTC Modified: 2004-09-26 20:34 UTC
From: kell_pt at users dot sf dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-09-25 (dev) OS: Any
Private report: No CVE-ID: None
 [2004-09-25 23:45 UTC] kell_pt at users dot sf dot net
The issue is pretty simple I've explained this problem before, I'm unsure why it hasn't been addressed - it's a design flaw and violates basic principles of what you'd expect from an OOP language.

Consider a static function in a base class, and a class that inherits from the above. In such a static function, self:: always refers to the class where the code was declared. That is wrong, it should be relative to the class the code was called from. It makes it impossible to have seperate variables in sub-classes sharing the same code.

It is easier watching the example, it speaks for itself. When "test()" runs, on the second call, it should be running within context of ClassB, not ClassA.

This is related to bug #28442, which was apparently ignored. Can someone at least explain what is the reasoning behind it working like that? I don't want to sound rude, but I know how it works, the distinctions between public and private, please don't patronize me (again). :)

Reproduce code:
class ClassA
   private static $base    = "Variable from ClassA";
   static function   test()
      print( self::$base . "\n" );

class ClassB extends ClassA
   private static $base = "Variable from ClassB";


Expected result:
Variable from ClassA
Variable from ClassB

Actual result:
Variable from ClassA
Variable from ClassA


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-26 20:34 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Sorry, you have a complete wrong idea og OO programming.

Static methods are bound/resolved at compile time. That is the compiler can replace self with the current class.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 06:01:26 2019 UTC