> 1) It seems that the getter and setter are not called on every single
> call.  For example, if I do the following:
>
> $bar = new foo;
> $bar->x = 'x';
>
> There is no output.  I would expect to see "Setting $this->x to x."
> Another example:
>
> $bar = new foo;
> $bar->y = 'y';
> echo $bar->y;
>
> I would expect this to see "The value of y is y." but instead I just
> get  'y' as output.  So when do the various setters/getters get used?
>
> 2) It seems that getters ignore the visibility of properties.  Why is
> this?  For example:
>
> $bar = new foo;
> echo $bar->z;
>
> I would expect this to throw an error about accessing a private
> member, but it outputs "The value of z is z." just fine.  If I remove
> the __get() overloader, an error is thrown.
>
> I'm guessing that the answer to all of my questions is some how
> wrapped up in visibility and overloading.  Unfortunately I cannot find
> any resource that documents the interactions.  TIA.
>

As I understand it, the __get and __set do not ignore visibility;
rather, they only work for accessing private members. If a property is
declared public, it does not need the __get and __set, so they aren't
used. Likewise, $bar->y is public since it was added dynamically
outside the class.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to