Bug #72292 [NEW]: Invalid foreach $value pointer if $value was iterated by reference previously

From: Date: Mon, 30 May 2016 16:52:04 +0000
Subject: Bug #72292 [NEW]: Invalid foreach $value pointer if $value was iterated by reference previously
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201350@lists.php.net to get a copy of this message
From:             cronfy at gmail dot com
Operating system: Linux Mint 17.1 Rebecca
PHP version:      5.6.22
Package:          Arrays related
Bug Type:         Bug
Bug description:Invalid foreach $value pointer if $value was iterated by reference previously

Description:
------------
PHP version 5.6.22 from PHP 5.6.22-2+donate.sury.org~trusty+1

When array is firstly iterated by reference for $value, and then
iterated without reference, last $value in second foreach is incorrect.



Test script:
---------------
$arr = [1, 2];

foreach ($arr as &$value) {}

foreach ($arr as $value) {
    echo "$value\n";
}


Expected result:
----------------
1
2

Actual result:
--------------
1
1

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72292&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72292&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72292&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72292&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72292&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72292&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72292&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72292&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72292&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72292&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72292&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72292&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72292&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72292&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72292&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72292&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72292&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72292&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72292&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72292&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72292&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#201350) next »