Re: Assign array with __get
| From: | mathieu.suen | Date: | Wed, 17 Mar 2010 14:40:40 +0000 |
| Subject: | Re: Assign array with __get | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47357@lists.php.net to get a copy of this message | ||
Ionut G. Stan wrote:
Hi, This is interesting and it appears the following change makes the snippet work as expected:I think is that the $this->anArray['bar'] = 4; Generate the following bytcode:public function &__get($name);
0 FETCH_OBJ_W $0 'anArray' 1 ZEND_ASSIGN_DIM $0, 'bar'Will the folloing : echo $this->anArray; $this->anArray['bar'];
0 FETCH_OBJ_R $0 'anArray'1 ECHO ... 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: 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 = array(); return $this->$name; } public function test() { $this->_zork['bar'] = 67; } } $a = 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