Bug #62901 [Nab->ReO]: foreach unexpectedly advances the internal array pointer
| From: | nikic@php.net | Date: | Thu, 13 Sep 2012 16:19:16 +0000 |
| Subject: | Bug #62901 [Nab->ReO]: foreach unexpectedly advances the internal array pointer | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173415@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62901&edit=1
ID: 62901
Updated by: nikic@php.net
Reported by: david at grudl dot com
Summary: foreach unexpectedly advances the internal array
pointer
-Status: Not a bug
+Status: Re-Opened
Type: Bug
Package: Variables related
PHP Version: 5.4.6
Block user comment: N
Private report: N
New Comment:
@laruence: Changing the array pointer is a change too. That's why foreach usually copies the
passed array.
So yes, this is a bug, but from a quick glance at the code I can't yet see why it happens.
Previous Comments:
------------------------------------------------------------------------
[2012-09-13 02:45:16] laruence@php.net
s ,write on copy, copy on write, ;<
------------------------------------------------------------------------
[2012-09-13 02:44:38] laruence@php.net
the same, although it is *copy* of a array, but still the same zval, PHP using
"write on copy". but the internalPointer's change is not considered as
"write"
here.
------------------------------------------------------------------------
[2012-09-13 01:51:19] david at grudl dot com
The point is: the iteration is not started on $this->arr, but it is started on array returned
from method getArr().
Foreach resets internal array pointer of completely different array.
------------------------------------------------------------------------
[2012-08-24 02:51:39] laruence@php.net
"When foreach first starts executing, the internal array pointer is automatically
reset to the first element of the array. " that means foreach change the internal
potinter of an array.
http://us3.php.net/manual/en/control-structures.foreach.php
------------------------------------------------------------------------
[2012-08-24 01:27:07] david at grudl dot com
Maybe this is not a bug, but i have read documentations carefully and there is nothing about this.
Could you send a link?
And one question: why function reset() uses reference, if there is no need to use reference to
advance internal array pointer?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=62901
--
Edit this bug report at https://bugs.php.net/bug.php?id=62901&edit=1