Bug #54351 [Opn->Bgs]: foreach loop corrupts data
| From: | aharvey@php.net | Date: | Tue, 22 Mar 2011 13:46:18 +0000 |
| Subject: | Bug #54351 [Opn->Bgs]: foreach loop corrupts data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159706@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54351&edit=1
ID: 54351
Updated by: aharvey@php.net
Reported by: drake at jetcode dot ru
Summary: foreach loop corrupts data
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
Operating System: CentOS
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This is documented behaviour: foreach with references doesn't behave
as you'd expect. Note the warning at http://php.net/foreach about this.
Previous Comments:
------------------------------------------------------------------------
[2011-03-22 14:41:33] drake at jetcode dot ru
Description:
------------
Affected PHP versions:
5.3.5
5.3.5
5.2.9
Bug reveals only in case when loop variables are SAME and second loop
variable is NOT passed by reference.
Test script:
---------------
$items = array
(
array('id' => 1),
array('id' => 2),
array('id' => 3),
array('id' => 4)
);
foreach ( $items as &$item )
{
$item['foo'] = 'bar';
}
// Expected $items id's: 1, 2, 3, 4
// Actualy: 1, 2, 3, 4
foreach ( $items as $item )
{
// do nothing
}
// Expected $items id's: 1, 2, 3, 4
// Actualy: 1, 2, 3, 3 <-- BUG!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54351&edit=1