Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51973 invoked from network); 12 Jul 2003 19:36:54 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 12 Jul 2003 19:36:54 -0000 Received: (qmail 19382 invoked from network); 12 Jul 2003 19:36:47 -0000 Received: from localhost (HELO andi-home.zend.com) (127.0.0.1) by localhost with SMTP; 12 Jul 2003 19:36:47 -0000 Message-ID: <5.1.0.14.2.20030712224053.02a43370@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sat, 12 Jul 2003 22:41:12 +0200 To: hudzilla@php.net,internals@lists.php.net In-Reply-To: <200307122003.38874.hudzilla@php.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] __get() and __set() in PHP 5 From: andi@zend.com (Andi Gutmans) References: <200307122003.38874.hudzilla@php.net> 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: > >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