Re: overprotective?
| From: | James Carr | Date: | Wed, 06 Apr 2005 17:26:31 +0000 |
| Subject: | Re: overprotective? | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37119@lists.php.net to get a copy of this message | ||
Actually, I've been having a small problem with PHP5 and protected
variables... if a class subclasses another class that has a protected
static variable, shouldn't the subclass be able to access it
statically? I tried self::$protected_var and parent::$protected_var,
both gave me access violation exceptions.
Is this a bug, or is this how PHP5's object model is supposed to be?
(of course, I to would prefer that variables be protected rather than
private, but this is something bugging me of late)
Thanks,
JC
On Apr 6, 2005 11:36 AM, Robin Ericsson <robin.ericsson@profecta.se> wrote:
> Lukas Smith wrote:
> > Protected properties cannot be modified from the outside either.
>
> No, but they can be modified by a class that extends the class.
>
> > Aside from that its not really efficient to force everything through
> > setters/getters in PHP, so I dont think we should proclaim this as evil
> > so easily.
>
> I don't proclaim getters/setters, I just say that using protected/public
> access on properties are dangerous unless the properties are treated as
> they could contain dangerous data from the owner of the properties.
>
> > Aside from this there is one serious drawback to labeling things with
> > private/protected. When using __call() to dynamically add functionality
> > through objects that are created ondemand and stored as properties you
> > quickly run into problems. There visibility "package" would probably be
> > wiser to use, even if its not supported in PHP5 (and therefore can only
> > be noted via an @access phpdoc comment).
>
> Not really sure what you mean here :)
>
> regards,
> Robin
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>