Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47395 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32872 invoked from network); 18 Mar 2010 13:40:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2010 13:40:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.152 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 72.14.220.152 fg-out-1718.google.com Received: from [72.14.220.152] ([72.14.220.152:25607] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/F7-20429-94D22AB4 for ; Thu, 18 Mar 2010 08:40:25 -0500 Received: by fg-out-1718.google.com with SMTP id 16so844756fgg.11 for ; Thu, 18 Mar 2010 06:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=MuwGhgBW/QtFkRDG5gVcKeddqmiKLTvZQev1sYXZTzw=; b=SjZ2D8BJ26U7ylHQNkOWaRdoOY1JEO38cop+nxVWzgevK7L+/QAlnwkelC4y2SrB3R phuvetUNopWcl1skSp3BgEsnlPyeFc50UKKvNJXg0eV1RhhOSLDVg2l09aLN6qWUb/uX KJrBM2DXQy7p5natWcMgu1QJsdnd7ALNMW508= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=iRtayC4qssDunSrkkU+sNHo/nEt3nDgnKyeXx9aXlIhKKlRamBlyVCzT8uiFSardVa BtVjofOBHxTmqNMdSaVlNaCovg6MNhDdlGvHlnDF3JeCTIqv3Rf18PXTYg2YIKCYWUwN OjbjCQoL26TQ2m3whxMp4Dn+0BmKq23xN504E= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.87.64.13 with SMTP id r13mr5579723fgk.20.1268912943574; Thu, 18 Mar 2010 04:49:03 -0700 (PDT) In-Reply-To: <4BA1DB19.1080608@easyflirt.com> References: <4BA0DF61.1010907@easyflirt.com> <4BA0E39C.7020600@gmail.com> <4BA0E9E8.8000404@easyflirt.com> <4BA1DB19.1080608@easyflirt.com> Date: Thu, 18 Mar 2010 12:49:03 +0100 X-Google-Sender-Auth: 635407865e9c5751 Message-ID: To: "mathieu.suen" Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Assign array with __get From: colder@php.net (Etienne Kneuss) Hello, On Thu, Mar 18, 2010 at 8:49 AM, mathieu.suen wrote: > Etienne Kneuss wrote: >> >> Hello, >> >> On Wed, Mar 17, 2010 at 3:40 PM, mathieu.suen >> wrote: >> >>> >>> Ionut G. Stan wrote: >>> >>>> >>>> Hi, >>>> >>>> This is interesting and it appears the following change makes the >>>> snippet >>>> work as expected: >>>> >>>> =A0 public function &__get($name); >>>> >>> >>> I think is that the $this->anArray['bar'] =3D 4; >>> >>> Generate the following bytcode: >>> >>> 0 =A0FETCH_OBJ_W =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0$0 =A0 =A0 =A0'anArray' >>> 1 =A0ZEND_ASSIGN_DIM =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$0, 'bar' >>> >>> Will the folloing : >>> >>> echo $this->anArray; >>> $this->anArray['bar']; >>> >>> 0 =A0FETCH_OBJ_R =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 $0 =A0 =A0 =A0'anArray' >>> 1 =A0ECHO >>> ... >>> >>> >>> >>> IMHO I think that the complexity of the VM is way to hight. >>> That is something I am strongly agree with Gilad Bracha on adding new >>> feature into a language: >>> >> >> What exactly would you like it do? You've two options: >> >> 1) __get, define the property, and then __set? >> 2) __get returns a ref that is modified >> >> The second option is taken by PHP. >> In your case you return a value, not a reference. >> > > I think there is a lot =A0to say why is not working but just look at thos= e > 2 execution: > > ---------------- 1st > class A > { > > =A0 =A0 =A0 =A0public function __get($name) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->$name =3D array(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return $this->$name; > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0public function test() > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->_zork; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->_zork['bar'] =3D 67; > =A0 =A0 =A0 =A0} > } > > $a =3D new A; > $a->test(); > > var_dump($a); > ---------------- 2nd > class A > { > > =A0 =A0 =A0 =A0public function __get($name) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->$name =3D array(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return $this->$name; > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0public function test() > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->_zork['bar'] =3D 67; > =A0 =A0 =A0 =A0} > } > > $a =3D new A; > $a->test(); > > var_dump($a); > ---------------- > Nothing strange or unexpected here, in "1st" you define $this->_zork in __get the first time you call it, meaning that you'll bypass the __get for your next $this->_zork['foo'] =3D 2; > > Adding something that don't have side effect make the side effect > work.... (more or less) > You almost have to know how the VM is implemented in other to know what > is going on. > Nothing is obvious. > >> >>> >>> Look at the last paragraph: >>> http://gbracha.blogspot.com/2009/09/systemic-overload.html >>> >>> >>>> >>>> On 3/17/10 3:55 PM, mathieu.suen wrote: >>>> >>>>> >>>>> Hi, >>>>> >>>>> >>>>> I came across a strange behavior when using the magic method __get an= d >>>>> some instance variable that should be an array. >>>>> Consider the following example: >>>>> >>>>> >>>>> class A >>>>> { >>>>> >>>>> public function __get($name) >>>>> { >>>>> $this->$name =3D array(); >>>>> return $this->$name; >>>>> } >>>>> >>>>> public function test() >>>>> { >>>>> $this->_zork['bar'] =3D 67; >>>>> } >>>>> } >>>>> >>>>> $a =3D new A; >>>>> $a->test(); >>>>> >>>>> var_dump($a); >>>>> >>>>> >>>>> So could someone explain me what is the semantic of the above >>>>> statements? >>>>> >>>>> Thanks >>>>> >>>>> >>>>> -- Mathieu Suen >>>>> >>> >>> --Mathieu Suen >>> >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> > > -- Mathieu Suen > > > > > --=20 Etienne Kneuss http://www.colder.ch