Chaining __set and __get in an expression

From: Date: Tue, 20 Jul 2004 04:26:46 +0000
Subject: Chaining __set and __get in an expression
Groups: php.internals 
Request: Send a blank email to internals+get-11363@lists.php.net to get a copy of this message
Given the class definition: <?php class Caller { private $x = array('a' => false); function __set($name, $value) { echo "setting\n"; $this->x[$name] = 'foo'; // intentially ignore value } function __get($name) { echo "getting\n"; return $this->x[$name]; } } $foo = new Caller(); $b = $foo->a = 'bar'; echo "b is " . $b . "\n"; /* output: setting b is bar */ ?> I sort of expected both __set and __get to be called. Is it concievable to have them both called? The other alternative If possible, is allowing a return value from __set() and using that value for the rest of the expression. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid!

« previous php.internals (#11363) next »