php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31125 two foreach loops in a row produce 2 diff results
Submitted: 2004-12-16 15:25 UTC Modified: 2004-12-16 15:43 UTC
From: dennis at inmarket dot lviv dot ua Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.1 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dennis at inmarket dot lviv dot ua
New email:
PHP Version: OS:

 

 [2004-12-16 15:25 UTC] dennis at inmarket dot lviv dot ua
Description:
------------
Hey, just DONT CLOSE THE BUG IF YOU DON'T EVEN READ IT!
(This is to tony2001@php.net, who closed bug 31118)
here is SIMPLER TEST CASE - no modifications of the array itself - two foreach loops show different contents


Reproduce code:
---------------
  $a = array('key1'=>'value1', 'key2'=>'value2', 'key3'=>'value3');
  foreach($a as $k=>&$v) {
    echo $k . '=' . $v . "\r\n";
  }
  foreach($a as $k=>$v) {
    echo $k . '=' . $v . "\r\n";
  }
// See? No values are modified!!! All explanations to other bugs do not cover this problem

Expected result:
----------------
key1=value1
key2=value2
key3=value3
key1=value1
key2=value2
key3=value3

Actual result:
--------------
key1=value1
key2=value2
key3=value3
key1=value1
key2=value2
key3=value2 <- should be 3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-16 15:43 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Then reopen the old report! Never submit something twice.
Duplicate of #31118
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 14:01:35 2024 UTC