Re: PHP5 and the DOM model
| From: | Robert Cummings | Date: | Fri, 18 Apr 2008 19:42:33 +0000 |
| Subject: | Re: PHP5 and the DOM model | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-273275@lists.php.net to get a copy of this message | ||
On Fri, 2008-04-18 at 13:17 -0600, Nathan Nobbe wrote:
> On Fri, Apr 18, 2008 at 1:02 PM, Robert Cummings <robert@interjinn.com>
> wrote:
>
> > What he means is don't ask for the data literally (by property name) ask
> > for it via a method. This allows wrapping the data in "work". This is a
> > moot issue in PHP since PHP allows trapping the property accessor.
>
>
> i dont think its moot. if your trapping it via __get() or __set() its still
> the same action; driving the client through a well defined interface; if it
> just happens to have the same name as the property itself, its still the
> same concept. you have the 'work' in the magic methods (at a minimum the
> initial part), instead of the getters and setters you would build yourself.
> and personally, i think it much cleaner to have separate methods for each of
> the properties rather than one big function which has to internally route
> control via some sort of logic, be it conditional, variable functions or
> w/e.
> besides which, for the magic methods to work, the variables have to be
> 'inaccessible' according to the docs which means protected, private, or
> non-existent; and barring the case of non-existent we are right back in the
> realm of encapsulation.
> unless you meant something different by 'trapping the property accessor';
> which you usually do pull some unexpected stuff so im waiting for your next
> clever example to prove me wrong :D
Nope, the point is moot. If I've made my properties publicly accessible,
now, due to the ability to trap via __get() or __set(), I can remove
them and handle them. Thus, I can retrospectively change the semantics
without care for having exposed the properties themselves. The point is
moot here because the option now exists to enhance properties at a later
date without the need to drive the enhancements through a method the
user must call (the details of __get() and __set() are hidden from the
user of the properties ;)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP