Bug #53725 [Opn->Bgs]: array was changed
| From: | aharvey@php.net | Date: | Thu, 13 Jan 2011 02:25:36 +0000 |
| Subject: | Bug #53725 [Opn->Bgs]: array was changed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157873@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53725&edit=1
ID: 53725
Updated by: aharvey@php.net
Reported by: Nikolay dot Syrisko at gmail dot com
Summary: array was changed
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
Operating System: windows 7
PHP Version: 5.2.17
Block user comment: N
Private report: N
New Comment:
This is bizarre, but documented behaviour, and is why the foreach
manual page recommends calling unset() on the loop variable when
using foreach in assign by reference mode.
Closing.
Previous Comments:
------------------------------------------------------------------------
[2011-01-12 14:20:45] Nikolay dot Syrisko at gmail dot com
Description:
------------
when I declare array and make foreach
step 1: foreach ($list as &$rec) {
then make
step 2: foreach ($list as $rec) {
and last element of $list at the moment "step 1" will broken after
executing of "step 2" with data of last element of $list at the moment
"step 2"
ps: checked under different versions including 5.2.17
when you make unset($rec) before calling "step 2" bug will not appear.
Test script:
---------------
$list = array(1, 2, 3, 4, 5);
foreach($list as &$rec);
echo '<pre>'.print_r($list, 1).'</pre>';
$list[] = 6;
$list[] = 7;
foreach($list as $rec);
echo '<pre>'.print_r($list, 1).'</pre>';
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53725&edit=1