Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63287 invoked from network); 27 Dec 2009 18:46:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Dec 2009 18:46:25 -0000 X-Host-Fingerprint: 76.233.72.111 unknown Received: from [76.233.72.111] ([76.233.72.111:20881] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/3D-26502-08BA73B4 for ; Sun, 27 Dec 2009 13:46:24 -0500 Message-ID: <22.3D.26502.08BA73B4@pb1.pair.com> To: internals@lists.php.net Date: Sun, 27 Dec 2009 13:46:21 -0500 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 References: <31.35.26502.C79573B4@pb1.pair.com> <1B.86.26502.42B673B4@pb1.pair.com> <4B3785AC.2000507@lerdorf.com> In-Reply-To: <4B3785AC.2000507@lerdorf.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 76.233.72.111 Subject: Re: [PHP-DEV] Unsetting loop variables at the end of the loop From: mwacker@cornellsun.com (Mike Wacker) Rasmus Lerdorf wrote: > 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 I have some thoughts on this for PHP 6, but here's something else that might be worth looking into. When you write [foreach ($ii as $i) ...], you usually expect that $i is not a reference variable (you would have used &$i otherwise). However, PHP allows this even if $i is already a reference variable (e.g.: it was used as such in a previous loop). Now look at this code: function f(&$x) { echo $x; } $x = 1; $args = array($x); call_user_func_array('f', $args); In PHP 5.3, this would trigger a warning and cause $x to be NULL inside of f because you mixed value and reference types in an improper way. This foreach() issue is essentially being caused by a similar evil mix of reference and value types. Perhaps [foreach ($ii as $i)] should trigger a warning if $i already exists as a reference variable.