Moriyoshi Koizumi wrote:
Moriyoshi Koizumi wrote:1) Each time before entering a foreach loop, php first tries to make a copy ofYes, 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?
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.
Oh, I found this issue was pointed out pretty long time ago.- Bug #5052 http://bugs.php.net/5052 - Bug #5270 (deleted?) http://news.php.net/article.php?group=php.dev&article=22668 http://news.php.net/article.php?group=php.dev&article=22672 http://news.php.net/article.php?group=php.dev&article=22673
[...]
I did search the database, and indeed I did see that bug (#5052) before posting my bug report. In fact, if you read my bug report, you will see that I even mention this bug, and yet another one (#14607). The bug you now found (#5052) is similar but NOT the same. In fact, it describes the opposite behaviour: the reporter there says that nested foreach's on two COPIES of the same array don't work, and that he can work around the bug by making a reference to the array. In my bug, nested foreach on a copy works, but not on a reference.Anyway, please search the database first, in order not to post the same kind of bug twice.
So there, I'm not such a complete idiot, you know. ;-)
Regards,
Vaclav Dvorak
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php