Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46517 invoked from network); 19 Mar 2010 13:34:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2010 13:34:54 -0000 Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.216 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.218.216 mail-bw0-f216.google.com Received: from [209.85.218.216] ([209.85.218.216:48335] helo=mail-bw0-f216.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/C4-19901-A7D73AB4 for ; Fri, 19 Mar 2010 08:34:50 -0500 Received: by bwz8 with SMTP id 8so3072206bwz.23 for ; Fri, 19 Mar 2010 06:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=z4CwNg87IDP1kxPo9Y1tQgguWO/0pQvIYIkWu1yIMr4=; b=ahkeygJEZEB9En4k2Qd8cQfHGItGd6batGu6t1ykCpaXb+vVrGJHX+S0WjNPI+xCRD xmSvL/b6sSR2S0LbKYeWTMOiXIFEKMDpNs9eo3nDYTQqN6hiWQiUsE/Z9hSd+o4pUzRK b2csri8iqWsXOeIfWLXC/FSSKnMdSEOG5/R/M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:cc:subject:references :in-reply-to:content-type:content-transfer-encoding; b=PDAFZmiKEFR05csrZmEKdFxR9XpFuHLsjzK+XrKN2Y8vt+xBdZYjnS+Yuz8oAOqb8t SF2DYfWaCVT4fDAr+l6TnkdXwc9clLbA1RdyYVhP05WwYVqzrfPSfKwgdFdErYbGnYnx rCPq6PNptADv6/wNZ5sQIE5CR38utvWhmeDnw= Received: by 10.204.156.213 with SMTP id y21mr1808110bkw.195.1269005686804; Fri, 19 Mar 2010 06:34:46 -0700 (PDT) Received: from l.local ([82.208.177.66]) by mx.google.com with ESMTPS id 14sm677980bwz.14.2010.03.19.06.34.44 (version=SSLv3 cipher=RC4-MD5); Fri, 19 Mar 2010 06:34:45 -0700 (PDT) Message-ID: <4BA37E11.9080403@gmail.com> Date: Fri, 19 Mar 2010 15:37:21 +0200 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 CC: internals@lists.php.net 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Assign array with __get From: ionut.g.stan@gmail.com ("Ionut G. Stan") 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 > 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 >>> >>> >> >> The sementic of >> >> $this->zork >> >> Should be the same as >> >> $this->__get('zork') >> > > $this->zork is only the same as $this->__get("zork") if zork is > undefined, this is perfectly normal and expected. > >> So in that respect it is not consistent. >> >> But anywhere I don't care if it change or not. >> >> Look at Scheme, Lisp and Smalltalk language. >> This is what I call consistent language. >> >> >> -- Mathieu Suen >> >> >> >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- Ionut G. Stan I'm under construction | http://blog.igstan.ro/