Re: foreach nastiness with references (bug #21702)
| From: | Moriyoshi Koizumi | Date: | Wed, 22 Jan 2003 22:56:18 +0000 |
| Subject: | Re: foreach nastiness with references (bug #21702) | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-93600@lists.php.net to get a copy of this message | ||
On Wed, Jan 22, 2003 at 04:12:18PM +0100, Vaclav Dvorak wrote:
> 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?
>
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
It seems that the commit I mentioned in the previous mail was just
for those problem reports. As no much discussion took place there,
all I can guess from them is there was already a fear of breaking BC.
Anyway, please search the database first, in order not to post the
same kind of bug twice.
Moriyoshi