Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46523 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17842 invoked from network); 27 Dec 2009 13:00:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Dec 2009 13:00:28 -0000 Received: from [127.0.0.1] ([127.0.0.1:22449]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id B8/35-26502-B6A573B4 for ; Sun, 27 Dec 2009 08:00:28 -0500 X-Host-Fingerprint: 76.233.72.111 unknown Received: from [76.233.72.111] ([76.233.72.111:17576] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/35-26502-C79573B4 for ; Sun, 27 Dec 2009 07:56:28 -0500 Message-ID: <31.35.26502.C79573B4@pb1.pair.com> To: internals@lists.php.net Date: Sun, 27 Dec 2009 07:56:22 -0500 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 76.233.72.111 Subject: Unsetting loop variables at the end of the loop From: mwacker@cornellsun.com (Mike Wacker) PHP's documentation for foreach states that if you iterate by reference [foreach ($ii as &$i) ...], you should unset $i after the loop. $i still points to the last element of the array - updating $i or reusing it will update the last element of the array. In short, why doesn't PHP automatically unset $i after the loop? I can't think of too many cases where you would want to hold on to that reference after you exit the loop, but I can think of a lot of scenarios where a user could accidentally tamper the array by using $i in a different context later on (especially since loop variable names often are reused).