Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47432 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 719 invoked from network); 19 Mar 2010 16:21:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2010 16:21:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=peter.e.lind@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=peter.e.lind@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.153 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: peter.e.lind@gmail.com X-Host-Fingerprint: 72.14.220.153 fg-out-1718.google.com Received: from [72.14.220.153] ([72.14.220.153:17017] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/E3-14064-3A4A3AB4 for ; Fri, 19 Mar 2010 11:21:56 -0500 Received: by fg-out-1718.google.com with SMTP id 22so88095fge.11 for ; Fri, 19 Mar 2010 09:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=8hT9/Kc7DhNUJsILZZIqhi4WOwe/b25xSw1HGHloVtY=; b=MBeTHrG+QyYt57Mhc2fdIVcM4/lflyGG+hIQ+b2sVVxziKMHMuHRVU88cO7BK38w9V 1B/qy04wMZoT7C7QpjcAQFnr0QCSswnHt1O9jl10OQLW1zbLCo09BCY7afuAWLOvh7TS 1ql+HMJmCCrkMvdB3KGu/52x2cJcYf7L28PWQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=KY6/4fiYEHggkm1DnBqfTR/zx5WRgPs8Wi5y2SLGfVu4o+KBb0vQiqDCFPJcZnJn8U 93OOalmIfFwFdbTOtQjKsy7y5+6yc8PssgHN3igO28eXhXMLwoZ83Hv7Q0Ci4aPaPe7i ub5MklRS6G9q4lNuu5OIoZmjVUmbfj/Kci9ik= MIME-Version: 1.0 Received: by 10.103.81.29 with SMTP id i29mr2065407mul.109.1269015712235; Fri, 19 Mar 2010 09:21:52 -0700 (PDT) In-Reply-To: <4BA3A147.2020506@easyflirt.com> References: <4BA0DF61.1010907@easyflirt.com> <4BA0E39C.7020600@gmail.com> <4BA0E9E8.8000404@easyflirt.com> <4BA1DB19.1080608@easyflirt.com> <660eb66f1003180224g5662ba1dtb123c3ee88a3a3e5@mail.gmail.com> <4BA25919.8090805@easyflirt.com> <4BA37E11.9080403@gmail.com> <4BA3A147.2020506@easyflirt.com> Date: Fri, 19 Mar 2010 17:21:32 +0100 Message-ID: <660eb66f1003190921g56d47d2cq2c8739433b55f890@mail.gmail.com> To: "mathieu.suen" Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Assign array with __get From: peter.e.lind@gmail.com (Peter Lind) 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 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: >> >> =C2=A0 =C2=A0class Foo >> =C2=A0 =C2=A0{ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0public $bar =3D array(); >> =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0$foo =3D new Foo; >> =C2=A0 =C2=A0$foo->bar[3] =3D 1; >> >> =C2=A0 =C2=A0var_dump($foo); >> >> >> >> >> ...is inconsistent with this: >> >> =C2=A0 =C2=A0class Foo >> =C2=A0 =C2=A0{ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0public function __get($property) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0{ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (! isset($this->$property)) = { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$this->$property = =3D array(); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return $this->$property; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0$foo =3D new Foo; >> =C2=A0 =C2=A0$foo->bar[3] =3D 1; >> >> =C2=A0 =C2=A0var_dump($foo); >> >> >> >> >> ...or even this: >> >> =C2=A0 =C2=A0class Foo >> =C2=A0 =C2=A0{ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0private $bar =3D array(); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0public function __get($property) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0{ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return $this->$property; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0$foo =3D new Foo; >> =C2=A0 =C2=A0$foo->bar[3] =3D 1; >> >> =C2=A0 =C2=A0var_dump($foo); >> >> >> Now, I'm not really sure this is that bad, as there may be use cases whe= re >> one would like to return different values every time __get is called. An= d, >> 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 >>> =C2=A0wrote: >>>> >>>> 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'] =3D 'blah'; no longer indirect= ly >>>>> calls __get as object::$zork now exists. >>>>> >>>>> =C2=A0In other words, this is down to you confusing passing a variabl= e 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, shoul= d >>>>> 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 > > --=20 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