#39114 [Opn->Bgs]: Foreach loop acces original array
| From: | tony2001@php.net | Date: | Tue, 10 Oct 2006 13:43:00 +0000 |
| Subject: | #39114 [Opn->Bgs]: Foreach loop acces original array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-103369@lists.php.net to get a copy of this message | ||
ID: 39114
Updated by: tony2001@php.net
Reported By: perso at cyprien dot org
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Debian stable
PHP Version: 5.1.6
New Comment:
Duplicate of bug #29992
Previous Comments:
------------------------------------------------------------------------
[2006-10-10 13:30:14] perso at cyprien dot org
Description:
------------
Foreach loop access original array when using references on a previous
loop.
Reproduce code:
---------------
<?php
$list = array( 1, 2, 3, 4 );
$new_list = array();
foreach( $list as $item ){
$z =& $new_list[];
$z = $item;
}
//unset( $z );
print_r( $new_list );
foreach( $new_list as $z ){
}
print_r( $new_list );
?>
Expected result:
----------------
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Actual result:
--------------
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 3
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39114&edit=1