Req #47380 [Opn->Fbk]: Ability for a superclass to declare that a class variable is per each subclass.

From: Date: Sat, 05 May 2018 19:54:58 +0000
Subject: Req #47380 [Opn->Fbk]: Ability for a superclass to declare that a class variable is per each subclass.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215091@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47380&edit=1 ID: 47380 Updated by: requinix@php.net Reported by: timlind at iafrica dot com Summary: Ability for a superclass to declare that a class variable is per each subclass. -Status: Open +Status: Feedback Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues PHP Version: 5.3.0beta1 Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2009-02-13 12:58:05] timlind at iafrica dot com Description: ------------ 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47380&edit=1

« previous php.bugs (#215091) next »