#29686 [Asn->Csd]: Bug when using foreach on an array that has been referenced before

From: Date: Thu, 14 Apr 2005 07:49:45 +0000
Subject: #29686 [Asn->Csd]: Bug when using foreach on an array that has been referenced before
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969367818@lists.php.net to get a copy of this message
ID: 29686 Updated by: vrana@php.net Reported By: swalk at prp dot physik dot tu-darmstadt dot de -Status: Assigned +Status: Closed Bug Type: Documentation problem Operating System: * PHP Version: 5.* Assigned To: et New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself." Previous Comments: ------------------------------------------------------------------------ [2005-02-15 00:22:56] tony2001@php.net Stefan, please look into it. If it works as expected, than it's a docu problem, probably. ------------------------------------------------------------------------ [2004-08-15 16:09:15] jakub dot phpbug at horky dot net Yes, sorry, now I see you are true. When I tested the example above I didn't try to comment out the line '$b =& $a;' so I thought the array is always using directly from foreach on each loop. So IMHO there is either badly written documentation or bad implementation (which is btw relevant to that two bugs I posted before). BUG UPDATE: Now I noticed that if you first unset() the $a variable before re-setting it to the string (or anything else), it is working properly. ------------------------------------------------------------------------ [2004-08-15 15:44:12] et@php.net 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. ------------------------------------------------------------------------ [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 et@php.net: > 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 :-) ------------------------------------------------------------------------ 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

« previous php.doc (#969367818) next »