Re: [patch] Zend/zend_object_handlers.c - bug #29378 (foreach() doesn't work with arrays returned by __get)

From: Date: Thu, 16 Sep 2004 13:24:39 +0000
Subject: Re: [patch] Zend/zend_object_handlers.c - bug #29378 (foreach() doesn't work with arrays returned by __get)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-12870@lists.php.net to get a copy of this message
AD>>> AD>>It looks like this bug was done intentionally (I'm not sure, just AD>>> AD>an>assumption), so zend_std_get_property_ptr_ptr() doesn't call AD>>> AD>__get. AD>>> AD>>> I'm not sure it should - this would confuse read/write operators like AD>>> object increments. AD>> AD>>Hmm.. could you provide any examples? AD>>I just want to test them with the patch and see maybe I can adopt it. The idea is that when r/w operator tries to work on object property, he can do it two ways: 1. call get_ptr_ptr, receive actual zval and do whatever it wants on it 2. some objects - like Java object representations, for example - can not return actual zval for property. For them, get_ptr_ptr returns null and then r/w operator call getter, does whatever it wants and calls setter on it. Now the question is what we want to do on the object having getters/setters in PHP - do we want it to behave like 1 or like 2? I'd say behaviour 2 is the most logical, since we don't even know if the getter returns modifyable variable - and in most cases it won't, so if you have some object $foo with getter and setter and you do $foo->x++, it should do get, then ++ on the result and the set, since if you just do get and ++, it probably won't have the necessary effect. We could approach this with another idea - making __get return reference (of course, if code author feels it is the right thing to do) and thus tell the get_ptr_ptr that it is "kosher" for using in r/w contexts. I did not explore this idea yet sufficiently to say that it would work in all the cases. This also needs still some handling in cases __get doesn't return the reference - the engine still have to resort to get/set. However, I am pretty sure that just using __get as it is on get_ptr_ptr would break the r/w operations in some cases. AD>> AD>>>I think it should be talen care of elsewhere. AD>> AD>>Any ideas where? In the place where get_ptr_ptr is called. I didn't look yet into this particular case - I'll try to do it when I'm back to work (meaning Friday or Sunday). -- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115

« previous php.internals (#12870) next »