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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cronfy at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC