Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47382 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15472 invoked from network); 17 Mar 2010 21:19:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Mar 2010 21:19:43 -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.153 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.153 fg-out-1718.google.com Received: from [72.14.220.153] ([72.14.220.153:13475] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/77-07776-E6741AB4 for ; Wed, 17 Mar 2010 16:19:42 -0500 Received: by fg-out-1718.google.com with SMTP id 16so627469fgg.11 for ; Wed, 17 Mar 2010 14:19:39 -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=+E0jw1/a6k+Qs0OSh48ulnQPgVJD6SVbbRqyTGfXrYs=; b=bAUs5WMZ2OFDO76XnBl5vQ7nn59kLbtWlgg03PuCnri1C5K64rN03pLGuQNRz9gYnv hsgpavmzbEE1CCIU2rZRrhNNGsXdYzfMfVO1RFXb4Aaw9pmoFZPGFNGqahUzwlQ3tGaJ UYiUyWEo8qOXRWbzaknfcYfmjmcRB62zz8eiM= 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=OSEjmTSTOunCQPiKhUVgonUdrg4p0oCjYtFdRoPprqUAPbHN2piwSHE1o9bT8NPN2F 3uYY6tYi+Maumcuzw1v8bIfNT2o1beKPYW07mDkG4t4ajg2IvT7Bi/8/IpSwv9kMjW4/ OhTDK78r/W3d5+YeWXaYJlM8PHUJBCehlYF7E= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.87.67.10 with SMTP id u10mr13285122fgk.28.1268860779063; Wed, 17 Mar 2010 14:19:39 -0700 (PDT) In-Reply-To: <4BA0E9E8.8000404@easyflirt.com> References: <4BA0DF61.1010907@easyflirt.com> <4BA0E39C.7020600@gmail.com> <4BA0E9E8.8000404@easyflirt.com> Date: Wed, 17 Mar 2010 22:19:39 +0100 X-Google-Sender-Auth: c730a671d2a2163d 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: webmaster@colder.ch (Etienne Kneuss) 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 snippe= t >> work as expected: >> >> =A0 =A0public 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. > > 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 and >>> 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 statement= s? >>> >>> Thanks >>> >>> >>> -- Mathieu Suen >>> >>> >>> >> > --Mathieu Suen > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Etienne Kneuss http://www.colder.ch