Re: bug when using foreach with references?
| From: | Richard K Miller | Date: | Thu, 22 Oct 2009 02:40:08 +0000 |
| Subject: | Re: bug when using foreach with references? | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-45866@lists.php.net to get a copy of this message | ||
I don't follow. Is this really the intended behavior? It seems quite unintuitive that the original array would be modified by *empty* loops.
Suppose I create an include file that loops through $_GET variables with references:
foreach ($_GET as &$get) { /* empty loop */ }
Subsequent foreach() loops on $_GET would cause corruption. Seems dangerous.
When would this behavior be desired?
!intuitive && !desired == bug ?
Richard
On Oct 21, 2009, at 8:19 PM, mm w wrote:
Richard, enumerator exhausted, repeat your sub-sequence again you will get it e.g pointer and pointed
<?php $items = array('apple', 'banana', 'carrot'); print_r($items); foreach ($items as &$item) { } print_r($items); foreach ($items as $item) { } print_r($items);