#47388 [Bgs]: Array Foreach Reference Broken
| From: | martin at itmission dot com | Date: | Mon, 16 Feb 2009 19:32:16 +0000 |
| Subject: | #47388 [Bgs]: Array Foreach Reference Broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-133885@lists.php.net to get a copy of this message | ||
ID: 47388
User updated by: martin at itmission dot com
Reported By: martin at itmission dot com
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows XP
PHP Version: 5.3.0beta1
New Comment:
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);
Previous Comments:
------------------------------------------------------------------------
[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-16 18:56:12] martin at itmission dot com
Changed category
------------------------------------------------------------------------
[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 http://bugs.php.net/?id=47388&edit=1