#43806 [Opn->Bgs]: Unexpected result using 'foreach'
| From: | derick@php.net | Date: | Thu, 10 Jan 2008 12:22:37 +0000 |
| Subject: | #43806 [Opn->Bgs]: Unexpected result using 'foreach' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121174@lists.php.net to get a copy of this message | ||
ID: 43806
Updated by: derick@php.net
Reported By: pepalegre at terra dot es
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: openSUSE 10.3
PHP Version: 5.2.5
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
(This has also been submitted a few times too)
Previous Comments:
------------------------------------------------------------------------
[2008-01-10 11:25:25] pepalegre at terra dot es
Description:
------------
If I declare a reference variable (&$value) and use it in a 'foreach'
and then I reuse it in the same loop like a normal variable ($value), I
have an unexpected result, array is modified!
Note that using another variable in the second 'foreach' the result is
Ok.
Reproduce code:
---------------
<?php
$v = array (1,2,3);
foreach($v as &$value);
print_r($v);
foreach($v as $value);
print_r($v);
?>
Expected result:
----------------
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Actual result:
--------------
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 2
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43806&edit=1