ID: 29686 Updated by: [EMAIL PROTECTED] Reported By: swalk at prp dot physik dot tu-darmstadt dot de -Status: Bogus +Status: Open Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.* New Comment:
I don't use register globals. But there are lots of servers which do. 1st, you're contradicting the Documentation, which clearly states that the array should be copied: "Note: Also note that foreach operates on a copy of the specified array and not the array itself." 2nd, you didn't specify the difference between using a reference variable and a normal variable. If you do foreach($array as $v) { array_push($array, 0); } modifying the array, it doesn't affect the loop. By your reasoning, it should? Please don't bogus it again, because it is either a problem with the documentation or with the implementation. Previous Comments: ------------------------------------------------------------------------ [2004-08-15 15:42:29] jakub dot phpbug at horky dot net Sorry for mistyping the bug numbers: bug #28939 and bug #29687 ------------------------------------------------------------------------ [2004-08-15 15:40:53] jakub dot phpbug at horky dot net To [EMAIL PROTECTED]: > especially the part with "Note: Also note > that foreach operates on a copy of the specified > array and not the array itself." Sorry, but that especially this paragraph is very obscure, because a subsequent sentence states "However, the internal pointer of the original array is advanced with the processing of the array." Furthermore, this is partially subject of recently opened bug #28939 or #28939. But there I really don't see any problem. Coincidental overwriting of registered global is IMO really not bug but stupidity of the author :-) ------------------------------------------------------------------------ [2004-08-15 15:27:49] [EMAIL PROTECTED] 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 Don't use register globals. And don't use it for example because of this problem. Second, a reference variable and a normal variable do NOT result in foreach copying the whole array. Instaed not accessing the data by ref [foreach($ar as &$data)] only results in copying the data. Therefor the array is still ste same and if you change the array in the loop then obviously you affect the loop. ------------------------------------------------------------------------ [2004-08-15 15:20:05] [EMAIL PROTECTED] Care to explain why doing $a =& $a; before the loop should affect the behaviour? In my (and some others whom i talked to) opinion that behaviour is bogus. And if it does make sense, it should be reflected in the documentation (where it isn't), because this caused someone an error with a high WTF factor in an application. Example: foreach ($_SESSION['something'] as $foo) { do_something; $something = "foo"; do_something_else; } Breaks on a server with register_globals on. ------------------------------------------------------------------------ [2004-08-15 15:07:56] [EMAIL PROTECTED] 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 . ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/29686 -- Edit this bug report at http://bugs.php.net/?id=29686&edit=1