From:             swalk at prp dot physik dot tu-darmstadt dot de
Operating system: Linux
PHP version:      5CVS-2004-08-15 (dev)
PHP Bug Type:     Arrays related
Bug description:  Bug when using foreach on an array that has been referenced before

Description:
------------
When using foreach with an array that has been referenced before, it
behaves oddly if you re-set the variable inside the loop - it loses the
array it originally worked on. That doesn't happen if you leave the line
creating the reference out.

Reproduce code:
---------------
<?php
$a = array(1,2,3);
$b =& $a; // this line causes the bug
          // $a =& $a; does it too
foreach($a as $v) {
    print "$v\n";
    $a = "foo"; 
}


Expected result:
----------------
1
2
3

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

Warning: Invalid argument supplied for foreach() in /home/et/test.php on
line 4

-- 
Edit bug report at http://bugs.php.net/?id=29686&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29686&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29686&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29686&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29686&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29686&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29686&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29686&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29686&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29686&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29686&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29686&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29686&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29686&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29686&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29686&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29686&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29686&r=float

Reply via email to