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

php.internals

Antony Dovgal

21 years ago
Another one patch for ZE. This one fixes the bug #29378. It looks like this bug was done intentionally (I'm not sure, just an assumption), so zend_std_get_property_ptr_ptr() doesn't call __get. Please look at the patch fro details.
-- Wbr, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com

Stanislav Malyshev

21 years ago
AD>>It looks like this bug was done intentionally (I'm not sure, just an AD>>assumption), so zend_std_get_property_ptr_ptr() doesn't call __get. I'm not sure it should - this would confuse read/write operators like object increments. I think it should be talen care of elsewhere.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115

Antony Dovgal

21 years ago
On Mon, 13 Sep 2004 18:50:15 +0300 (IDT) Stanislav Malyshev <stas@zend.com> wrote:
> AD>>It looks like this bug was done intentionally (I'm not sure, just > AD>an>assumption), so zend_std_get_property_ptr_ptr() doesn't call > AD>__get. > > I'm not sure it should - this would confuse read/write operators like > object increments.
Hmm.. could you provide any examples? I just want to test them with the patch and see maybe I can adopt it.
>I think it should be talen care of elsewhere.
Any ideas where?
-- Wbr, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com

Stanislav Malyshev

21 years ago
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

Marcus Börger

21 years ago
Hello Stanislav, Thursday, September 16, 2004, 3:24:39 PM, you wrote: 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.
That's a pretty nice solution.
> We could approach this with another idea - making __get return reference > (of course, if code author feels it is the right thing to do) [...]
Forget that, c-level __get implementations cannot return a zval by reference. Best regards, Marcus mailto:helly@php.net