Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46533 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97182 invoked from network); 28 Dec 2009 01:37:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2009 01:37:33 -0000 X-Host-Fingerprint: 95.31.13.88 xdmitri2.static.corbina.ru Received: from [95.31.13.88] ([95.31.13.88:4110] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/91-26502-CDB083B4 for ; Sun, 27 Dec 2009 20:37:33 -0500 Message-ID: <8A.91.26502.CDB083B4@pb1.pair.com> To: internals@lists.php.net References: <31.35.26502.C79573B4@pb1.pair.com> <1B.86.26502.42B673B4@pb1.pair.com> <4B3785AC.2000507@lerdorf.com> Date: Mon, 28 Dec 2009 04:37:27 +0300 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5843 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-RFC2646: Format=Flowed; Original X-Posted-By: 95.31.13.88 Subject: Re: [PHP-DEV] Unsetting loop variables at the end of the loop From: dmda@yandex.ru ("jvlad") "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. -jv