Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45873 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61808 invoked from network); 22 Oct 2009 17:06:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2009 17:06:37 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.226 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.226 mail-fx0-f226.google.com Received: from [209.85.220.226] ([209.85.220.226:41150] helo=mail-fx0-f226.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/A4-21514-B1190EA4 for ; Thu, 22 Oct 2009 13:06:37 -0400 Received: by fxm26 with SMTP id 26so12309541fxm.23 for ; Thu, 22 Oct 2009 10:06:31 -0700 (PDT) Received: by 10.103.84.2 with SMTP id m2mr4214549mul.107.1256231191033; Thu, 22 Oct 2009 10:06:31 -0700 (PDT) Received: from ?192.168.200.148? (c-69-181-146-64.hsd1.ca.comcast.net [69.181.146.64]) by mx.google.com with ESMTPS id e8sm271387muf.29.2009.10.22.10.06.29 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 22 Oct 2009 10:06:30 -0700 (PDT) Message-ID: <4AE09112.7050008@lerdorf.com> Date: Thu, 22 Oct 2009 10:06:26 -0700 User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105) MIME-Version: 1.0 To: Richard K Miller CC: internals@lists.php.net References: <84898698-728C-44ED-BF7A-E0E02C111F68@gmail.com> <4AE00CE9.9050602@daylessday.org> <2FEC738F-A4EF-4853-8CC7-D4DAF97D892C@gmail.com> <4AE07B61.7030308@lerdorf.com> <7D2CE34C-177D-47BD-B758-433FCEF6C733@gmail.com> In-Reply-To: <7D2CE34C-177D-47BD-B758-433FCEF6C733@gmail.com> X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] bug when using foreach with references? From: rasmus@lerdorf.com (Rasmus Lerdorf) Richard K Miller wrote: >> It is one of these things that make perfect sense when you think about >> it a little bit. Yes, it catches some people, just like strpos() >> returning character position 0 on a first-char match catches some >> people. There is no way to fix things like these without completely >> breaking things. If we had strpos not use 0-based string positions or >> if we arbitrarily broke references after loops, all sorts of other >> things would start breaking and no longer make sense. >> >> -Rasmus > > Rasmus, > > Thanks for your reply. With respect, this seems to be in a different > class from matching strings with character position 0, IMO. > > What about unsetting the iterator before foreach() looping begins? The > iterator is altered anyway, so would this prevent it from being > "attached" to previous foreach() iterations? It would be arbitrarily breaking an explicit reference. I know I have code lying around that relies on multiple loops cleaning up a big complicated multi-level array. I do ugly things with references into that array and it would completely break if PHP magically deleted my references whether they are in the iterator or elsewhere. This has been this way for 6+ years and it is well documented on the http://php.net/foreach page. (see the big red warning box) -Rasmus