#35106 [Fbk->Opn]: nested foreach fails when the array was sometime before referenced

From: Date: Sat, 05 Nov 2005 14:00:59 +0000
Subject: #35106 [Fbk->Opn]: nested foreach fails when the array was sometime before referenced
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87615@lists.php.net to get a copy of this message
 ID:               35106
 User updated by:  olympnn at nm dot ru
 Reported By:      olympnn at nm dot ru
-Status:           Feedback
+Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows XP Sp2
 PHP Version:      5.0.5
 New Comment:

Downloaded Windows version, nothing new.
Script

<?
print(PHP_VERSION."\n");
$a=array("1","2");
$b=&$a;//*
foreach($a as $i){
    print($i);
    foreach($a as $p);//*
}
?>

returns

5.0.6-dev
1

expected

5.0.6-dev
12

When commenting any of two lines marked *, output becomes

5.0.6-dev
12


Previous Comments:
------------------------------------------------------------------------

[2005-11-04 17:04:00] derick@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

------------------------------------------------------------------------

[2005-11-04 16:57:11] olympnn at nm dot ru

Description:
------------
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.

Thanks.

Reproduce code:
---------------
<?
$a=array("1","2");
$b=&$a;//*
foreach($a as $i){
    print($i);
    foreach($a as $p);//*
}
?>

Expected result:
----------------
12

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35106&edit=1


Thread (6 messages)

« previous php.bugs (#87615) next »