Re: foreach nastiness with references (bug #21702)
| From: | Vaclav Dvorak | Date: | Wed, 22 Jan 2003 15:12:18 +0000 |
| Subject: | Re: foreach nastiness with references (bug #21702) | ||
| References: | 1 2 3 4 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-93597@lists.php.net to get a copy of this message | ||
Moriyoshi Koizumi wrote:
I tried to answer this question in the bug report page. [...]
1) Each time before entering a foreach loop, php first tries to make a copy of the array being iterated. 2) In case the array variable is either referenceing another variable or referenced by another variable, no copy is made here and the original array is used instead. Because of this behaviour, the original's internal array pointer increases in the loop eventually.Yes, I understand this. What I don't understand is WHY is it so? Why is foreach handling references specially? Why is your point 2) there? I probably don't see all the consequences (I know little about PHP/Zend internals and have found no documentation), but wouldn't the fix be as simple as changing the SEPARATE_ZVAL_IF_NOT_REF into SEPARATE_ZVAL on line 2251 of Zend/zend_execute.c? URL: http://lxr.php.net/source/php4/Zend/zend_execute.c#2251 (search for "case ZEND_FE_RESET:" if line numbers shift). BTW, what's the relation of http://lxr.php.net/source/php4/Zend/ and http://lxr.php.net/source/Zend/ ? Vaclav Dvorak <vdvo@vdvo.net>