Bug #47388 [Com]: Array Foreach Reference Broken
| From: | chealer at gmail dot com | Date: | Thu, 01 Jan 2015 20:19:33 +0000 |
| Subject: | Bug #47388 [Com]: Array Foreach Reference Broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189582@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=47388&edit=1
ID: 47388
Comment by: chealer at gmail dot com
Reported by: martin at itmission dot com
Summary: Array Foreach Reference Broken
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Windows XP
PHP Version: 5.3.0beta1
Block user comment: N
Private report: N
New Comment:
The problematic behavior behind this issue is being tracked in #62132.
Previous Comments:
------------------------------------------------------------------------
[2009-02-16 19:32:15] martin at itmission dot com
The error is in my code. Sorry. Always unset variables after a foreach with a reference unless you
know what you are doing.
unset($v);
------------------------------------------------------------------------
[2009-02-16 19:15:58] derick@php.net
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.
.
------------------------------------------------------------------------
[2009-02-16 18:57:13] martin at itmission dot com
Also happens in 5.2.8
------------------------------------------------------------------------
[2009-02-14 19:47:28] martin at itmission dot com
Description:
------------
When using foreach on an array using the reference syntax, stuff breaks later.
Reproduce code:
---------------
<?php
$a = array(0, 1, 2, 3, 4);
foreach($a as $k => &$v)
{
$v++;
}
foreach($a as $k => $v)
{
echo("$k => $v\n");
}
?>
Expected result:
----------------
0 => 1
1 => 2
2 => 3
3 => 4
4 => 5
Actual result:
--------------
0 => 1
1 => 2
2 => 3
3 => 4
4 => 4
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=47388&edit=1