|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-05-05 19:54 UTC] requinix@php.net
-Status: Open
+Status: Feedback
-Package: Feature/Change Request
+Package: *General Issues
[2018-05-05 19:54 UTC] requinix@php.net
[2018-06-24 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 06:00:02 2025 UTC |
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.