ID: 29686 Updated by: [EMAIL PROTECTED] Reported By: swalk at prp dot physik dot tu-darmstadt dot de -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Linux PHP Version: 5CVS-2004-08-15 (dev) New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php . Previous Comments: ------------------------------------------------------------------------ [2004-08-15 15:05:48] [EMAIL PROTECTED] Please read properly before posting. And also read http://www.php.net/foreach , especially the part with "Note: Also note that foreach operates on a copy of the specified array and not the array itself." And as was said, it only happens if you do $a =& $a; before the foreach clause. If you don't do it, you get the expected result. ------------------------------------------------------------------------ [2004-08-15 14:55:40] jakub dot phpbug at horky dot net I'm afraid that is caused just by the line $a = "foo"; which re-sets the $a variable to string, so it is no longer an array and can't be enumerated by next loop... ------------------------------------------------------------------------ [2004-08-15 12:37:33] swalk at prp dot physik dot tu-darmstadt dot de 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 this bug report at http://bugs.php.net/?id=29686&edit=1