|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35106 nested foreach fails when array variable has a reference
Submitted: 2005-11-04 16:57 UTC Modified: 2007-01-10 16:01 UTC
Avg. Score:3.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: olympnn at nm dot ru Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-11-05 (cvs) OS: *
Private report: No CVE-ID:
 [2005-11-04 16:57 UTC] olympnn at nm dot ru
When I execute the code, it seems that the outer foreach is executed only once. When I comment any of lines marked *, the (outer) foreach executes twice.

This bug seems to be very like to bug # 21702, but here the situation is much more strange: I do not use $b in foreaches at all! So it's very strange that the foreach behavior differs when the array was referenced sometime or not.


Reproduce code:
foreach($a as $i){
    foreach($a as $p);//*

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-05 16:37 UTC]
Verified. Dmitry, check this out.
 [2006-02-10 20:48 UTC] brion at wikimedia dot org
Note that the same happens with global variables accessed 
from a function with the 'global' statement. Since globals 
work via references, this seems to be the same issue.

This was closed as "won't fix" in 2003:

I sincerely hope the opinion has changed in the intervening 
time, as it's pretty clearly poor behavior.
 [2007-01-10 16:01 UTC]
Fixed in CVS HEAD and PHP_5_2
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Fri Oct 09 03:01:29 2015 UTC