Andi,

Wouldn't it be more useful if they worked for all variables, or is there a 
design reason why they work as they do currently?


--Paul


> Yes, you are right. They only work if the variable is not defined.
>
> Andi
>
> At 08:03 PM 12/7/2003 +0100, Paul Hudson wrote:
> >All,
> >
> >I've been poking around with these two functions while testing the build
> > from CVS, and am not sure how they're supposed to work.  From what I can
> > gather, they are only called when changing a variable that wasn't in the
> > class definition.  I say that because I took the example script from
> >http://uk.php.net/zend-engine-2.php and stripped it down to this:
> >
> ><?php
> >class Setter {
> >         public $n;
> >         public $z;
> >
> >         function __get($nm) {
> >                 print "Getting [$nm]\n";
> >         }
> >
> >         function __set($nm, $val) {
> >                 print "Setting [$nm] to $val\n";
> >         }
> >}
> >
> >$foo = new Setter();
> >$foo->n = 1;
> >$foo->z++;
> >$foo->z++;
> >?>
> >
> >That script outputs nothing, despite reading and writing to z twice, and
> >writing to n once.  If you comment out the "public $n;" and "public $z;"
> >lines, you get the following output:
> >
> >Setting [n] to 1
> >Getting [z]
> >Setting [z] to 1
> >Getting [z]
> >Setting [z] to 1
> >
> >... which is what I was expecting.
> >
> >Are __get() and __set(), then, only supposed to work with non-declared
> >variables, or am I doing something wrong?
> >
> >Thanks,
> >
> >
> >--Paul
> >
> >--
> >PHP Internals - PHP Runtime Development Mailing List
> >To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to