php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72292 Invalid foreach $value pointer if $value was iterated by reference previously
Submitted: 2016-05-30 16:52 UTC Modified: 2016-05-30 20:44 UTC
From: cronfy at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.6.22 OS: Linux Mint 17.1 Rebecca
Private report: No CVE-ID: None
 [2016-05-30 16:52 UTC] cronfy at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-30 20:44 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-05-30 20:44 UTC] requinix@php.net
See bug #71458
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC