Re: Concerns over handling of bug #49105
| From: | Greg Beaver | Date: | Thu, 30 Jul 2009 21:06:47 +0000 |
| Subject: | Re: Concerns over handling of bug #49105 | ||
| References: | 1 2 3 | Groups: | php.qa |
| Request: | Send a blank email to php-qa+get-65266@lists.php.net to get a copy of this message | ||
Alexander Trauzzi wrote:
> The three scopes self::, static:: and parent:: allow for this to be
> explicit. Why deny them their implied use? Why would any class even want
> to refer to the parent property as a default when the static:: scope is
> used? It's already saying "I want this in a runtime scope, not load time."
>
> The two questions are:
>
> 1. Why wouldn't PHP want to duplicate properties in subclasses? Again,
> especially given the abundance of useful scopes like parent:: static:: and
> self::.
This is how Java works, perhaps you are coming from that background?
> 2. Why would a call to a static::$property fall through to the parent class?
The same reason that a call to $this->property falls through to the
parent class: because that is the way PHP was designed.
Changing this would literally break every single existing OOP
application written since PHP 4.0.0 was released. Want an example?
Pyrus (see http://pear2.php.net) stores its configuration using a
Config
class, and also has the ability to store a snapshot of a configuration
and to use that. The Config\Snapshot class needs to be able to use the
parent variables, but overrides the way they are handled by extending a
few methods.
What everyone is trying to tell you is that this is a core design
element of the language, and changing it would wreak havoc for no benefit.
If you want to hide a variable from a child class, you have several
options in PHP.
1) private. Declare the variable as private, and the child class will
not access the parent variable.
2) __get()/__static_get(). Implement __get()/__static_get()
3) require your users to define any static variables they want to handle
differently, and use self:: to access them. static:: is explicitly
designed to provide polymorphism for static variables, something we
already get for class properties
In short, the reason this bug was "bogus"ed was because it is simply not
even possible to consider changing this - it would be like suggesting
that PHP change all variable names so that they must start with # - it's
not going to happen, ever.
Greg