Bug #68457 [NEW]: Reference by pointer inaccurate in foreach
| From: | mberding at dtoolbox dot com | Date: | Wed, 19 Nov 2014 22:28:31 +0000 |
| Subject: | Bug #68457 [NEW]: Reference by pointer inaccurate in foreach | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-188695@lists.php.net to get a copy of this message | ||
From: mberding at dtoolbox dot com
Operating system: CentOS
PHP version: 5.4.35
Package: Variables related
Bug Type: Bug
Bug description:Reference by pointer inaccurate in foreach
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 bug report at https://bugs.php.net/bug.php?id=68457&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68457&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68457&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68457&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68457&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68457&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68457&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68457&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68457&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68457&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68457&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68457&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68457&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68457&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68457&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68457&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68457&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68457&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68457&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68457&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68457&r=mysqlcfg