Have you considered that perhaps you're trying to use the wrong language for what you're doing? PHP does what it does now consistently (in this regard) - what you're suggesting breaks that consistency. To gain what, exactly?
On 19 March 2010 17:07, mathieu.suen <mathieu.s...@easyflirt.com> wrote: > Right I could work around the issue with the return by reference without any > problem. > I am still thinking that if you try to write a meta-circular interpreter you > gonna work very hard > to make this subtleties worked. And according to "Shriram Krishnamurthi" in > his textbook PLAI: > > " a truly powerful language is one that makes it easy to write its > meta-circular interpreter." > > -- Mathieu Suen > > > > Ionut G. Stan wrote: >> >> I guess what Mathieu is trying to say is that this: >> >> class Foo >> { >> public $bar = array(); >> } >> >> $foo = new Foo; >> $foo->bar[3] = 1; >> >> var_dump($foo); >> >> >> >> >> ...is inconsistent with this: >> >> class Foo >> { >> public function __get($property) >> { >> if (! isset($this->$property)) { >> $this->$property = array(); >> } >> >> return $this->$property; >> } >> } >> >> $foo = new Foo; >> $foo->bar[3] = 1; >> >> var_dump($foo); >> >> >> >> >> ...or even this: >> >> class Foo >> { >> private $bar = array(); >> >> public function __get($property) >> { >> return $this->$property; >> } >> } >> >> $foo = new Foo; >> $foo->bar[3] = 1; >> >> var_dump($foo); >> >> >> Now, I'm not really sure this is that bad, as there may be use cases where >> one would like to return different values every time __get is called. And, >> as I wrote in a previous email, there are ways to work around this >> inconsistency by using return by reference, so everybody can be happy. I >> think. >> >> >> >> On 3/19/10 4:56 AM, Etienne Kneuss wrote: >>> >>> On Thu, Mar 18, 2010 at 5:47 PM, mathieu.suen >>> <mathieu.s...@easyflirt.com> wrote: >>>> >>>> Peter Lind wrote: >>>>> >>>>> On the contrary, it's quite obvious what's going on. In both examples >>>>> __get() returns an array as PHP would normally do it (i.e. NOT by >>>>> reference) which means that if you try to modify that you'll end up >>>>> modifying nothing much. However, in your second example, the point at >>>>> which you call __get() indirectly comes before the assign to the zork >>>>> array - hence, the $this->zork['blah'] = 'blah'; no longer indirectly >>>>> calls __get as object::$zork now exists. >>>>> >>>>> In other words, this is down to you confusing passing a variable by >>>>> reference and passing it by value: PHP normally passes arrays by >>>>> value, so when __get() returns an array, you're working on a copy of >>>>> the array you returned. As someone noted earlier, you can easily >>>>> change the behaviour of __get to return variables by reference, should >>>>> you want to. However, I personally wouldn't want this to be default >>>>> behaviour as that would make debugging apps much more annoying - >>>>> things should be consistent, even if consistency at times confuse >>>>> people. >>>>> >>>>> Regards >>>>> Peter >>>>> >>>>> >>> >>> > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 </hype> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php