Bug #68457 [Opn->Nab]: Reference by pointer inaccurate in foreach
| From: | rasmus@php.net | Date: | Wed, 19 Nov 2014 22:32:33 +0000 |
| Subject: | Bug #68457 [Opn->Nab]: Reference by pointer inaccurate in foreach | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188696@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68457&edit=1
ID: 68457
Updated by: rasmus@php.net
Reported by: mberding at dtoolbox dot com
Summary: Reference by pointer inaccurate in foreach
-Status: Open
+Status: Not a bug
Type: Bug
Package: Variables related
Operating System: CentOS
PHP Version: 5.4.35
Block user comment: N
Private report: N
New Comment:
http://php.net/foreach
Previous Comments:
------------------------------------------------------------------------
[2014-11-19 22:28:30] mberding at dtoolbox dot com
Description:
------------
In the code below the last element in the $a array is replaced with a copy of the second-to-last
element.
Tested and confirmed in PHP versions: 5.3.3, 5.4.34, 5.6.2
Tested OS: CentOS 6.5, 7
Test script:
---------------
//Test Script:
//------------
$a = array(1,2,3);
foreach($a AS &$y) {
$y = $y*2;
}
foreach($a AS $y) {
echo $y.', ';
}
Expected result:
----------------
2,4,6,
Actual result:
--------------
2,4,4,
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68457&edit=1