Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46534 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99344 invoked from network); 28 Dec 2009 01:57:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2009 01:57:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.211.202 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.211.202 mail-yw0-f202.google.com Received: from [209.85.211.202] ([209.85.211.202:38927] helo=mail-yw0-f202.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/F1-26502-170183B4 for ; Sun, 27 Dec 2009 20:57:05 -0500 Received: by ywh40 with SMTP id 40so10435980ywh.26 for ; Sun, 27 Dec 2009 17:57:03 -0800 (PST) Received: by 10.150.70.4 with SMTP id s4mr9796772yba.21.1261965423405; Sun, 27 Dec 2009 17:57:03 -0800 (PST) Received: from ?192.168.200.22? (c-98-234-184-167.hsd1.ca.comcast.net [98.234.184.167]) by mx.google.com with ESMTPS id 8sm4556481yxg.6.2009.12.27.17.57.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 27 Dec 2009 17:57:02 -0800 (PST) Message-ID: <4B38106C.2080806@lerdorf.com> Date: Sun, 27 Dec 2009 17:57:00 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: jvlad CC: internals@lists.php.net References: <31.35.26502.C79573B4@pb1.pair.com> <1B.86.26502.42B673B4@pb1.pair.com> <4B3785AC.2000507@lerdorf.com> <8A.91.26502.CDB083B4@pb1.pair.com> In-Reply-To: <8A.91.26502.CDB083B4@pb1.pair.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Unsetting loop variables at the end of the loop From: rasmus@lerdorf.com (Rasmus Lerdorf) jvlad wrote: > "Rasmus Lerdorf" wrote in message > news:4B3785AC.2000507@lerdorf.com... >> We can't just randomly reset variables based on their scope in this one >> specific case. If we are going to "fix" this, it should be done by >> introducing a way to do proper local scope variables. Resetting a >> reference simply because it is convenient in this one case would be >> completely inconsistent. >> >> -Rasmus > > Rasmus, > it's not required to do anything like that and I myself would be against any > random resets, > but it's definitely not the case. There is nothing random and everything is > well determinted. > As I see the problem, it would be sufficient to fix the FOREACH and make it > working in the following way: > For example, say we have $a=array('apple', 'orange'); > and iterate through $a values: > foreach($a as &$v) ... > as an initial step, $v MUST be assigned to the very first element of $a > which 'apple'. It should be done regadless of the > value that might be assigned to $v before (that's the first change) > On the next step, it will be advanced by one and assign $v to point to > 'orange' > On the next iteration, it MUST also be advanced by one, reach the End Of the > Array, so it should assign NULL (or FALSE?) value to $v, > then finish the loop. > > Isn't it what would work in a clearer way? > > Evenmore, this change would make the foreach working more consistent with > each()/next()/prev() - they return FALSE as soon as internal pointer > reaches either boundary of the array. Neither stick with last element, like > foreach(). > > If you think current behaviour of foreach is useful, it's possible to > introduce new setting in php.ini, say strict_foreach=ON that will break > BC, but make foreach working clearer. No chance. No .ini settings, and I still maintain it is inconsistent. So, if I write this: $a = array(1); $b = 0; $c = &$b; $c = $a[0]; Would you agree that $b should be 1 at this point? If so, just because I rewrite that code like this: $a = array(1); $b = 0; $c = &$b; foreach($a as $c); Now you are arguing that $b should not be 1? The two pieces of code are identical and since we do not have a block scope and there is no syntax for explicitly indicating that $c is somehow a different $c or that we should wipe out the $c that existed before the foreach, I can see no sane reason to break the language for this case. And I don't see how your prev/next stuff has anything to do with this. -Rasmus