|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47380 Ability for a superclass to declare that a class variable is per each subclass.
Submitted: 2009-02-13 12:58 UTC Modified: 2018-06-24 04:22 UTC
From: timlind at iafrica dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.3.0beta1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: timlind at iafrica dot com
New email:
PHP Version: OS:


 [2009-02-13 12:58 UTC] timlind at iafrica dot com
The new static:: keyword (poorly named, wouldn't virtual:: be better?) has introduced the ability for a super-class to execute in the context of the class that specializes it.

This has allowed the super-class to access attributes that are (re)declared in the subclass, allowing specialized functions to be called.

For this to happen, the sub-class needs to have statically declared and defined the method (if there was such a method in the super-class in the first place). For methods, this is fine, because for a method to be overriden by a subclass, it will of course need to be defined by the subclass. 

But for attributes, the subclass has no concern with or reason to redeclare the attribute, so it should be possible for the super class to specify that a static attribute be redeclared for the subclass.

Reproduce code:
class Super {
  static self::$variable = 'super';
  function __construct() {
    static::$variable = 'sub';


class Sub extends Super {


new Sub();
Super::$variable; # => super
Sub::$variable; # => sub

Expected result:
Super::variable should be untouched, and Sub::variable should be affected by the statement in Super::__construct.

self::$var makes sense in comparison to the opposite which is Super::$var (what static $var is currently a shorthand for).

Actual result:
Invalid syntax.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-05 19:54 UTC]
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2018-05-05 19:54 UTC]
Old request is old.

This is asking for private variables that are not private - I don't know how that is supposed to work, static or not. Remember that stuff like "parent::" and "self::" and "static::" are not about static access but about determining which class's data to reference; static::$variable means to reference the $variable member of whatever the statically-called/LSB class was, regardless of whether the variable is instanced or static.

Is there any interest in this idea? What are the use cases for it that aren't better solved through inheritance?
 [2018-06-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 09:01:29 2024 UTC