Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71668 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92069 invoked from network); 28 Jan 2014 13:25:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2014 13:25:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:58200] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/1E-01140-ADFA7E25 for ; Tue, 28 Jan 2014 08:25:47 -0500 Received: by mail-wg0-f47.google.com with SMTP id m15so749641wgh.2 for ; Tue, 28 Jan 2014 05:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=DlyZ0MTkL/PzqaBBM1hWJOvxLXjyqWeNDt8bEu7KLQY=; b=ixsHviotN3ns90ExabGtIFRBbfu92Emo5YmktGJMONjbiXyuifzWdqdZNV4n/MAix5 dkeWz3laCn4FWidZWAmFuHio1n7oHe1rZiDgrOED7+lF+Y5sxksS59fZLT9aQyBON0z1 R2+cp9UUJp1YXoRuxr60BnMcsxCTGiowz5kg7NhZc5qkqk4YWibfnmte/Cnv/G3dAsCv g0fAsPk36r/mM1OPGxMmJzCqzpi/LQAQXGFWVrBreqym1W4tC+mZG90ZKyQGYaIgcDo6 p8pc29OWKovDOsI6DZwTdwNTHM+De56lq4PYc0WyeyTzRGZ38KrMfyJN6ot1zfuPN8l8 PvbQ== X-Received: by 10.180.98.199 with SMTP id ek7mr1980493wib.21.1390915543188; Tue, 28 Jan 2014 05:25:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.11.135 with HTTP; Tue, 28 Jan 2014 05:25:23 -0800 (PST) In-Reply-To: References: <1796143171.126442.1390903281925.open-xchange@app2.ox.registrar-servers.com> Date: Tue, 28 Jan 2014 14:25:23 +0100 Message-ID: To: Sebastian Krebs Cc: Andrea Faulds , PHP internals list Content-Type: multipart/alternative; boundary=f46d041826a0dd87cb04f107c264 Subject: Re: [PHP-DEV] Lexical scoping From: linepogl@gmail.com (Lazare Inepologlou) --f46d041826a0dd87cb04f107c264 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2014-01-28 Sebastian Krebs > 2014-01-28 Andrea Faulds > > > Good morning, > > > > Perhaps a future version of PHP (PHP 6? 5.7?) could have lexical scopin= g > > with a > > "let" keyword? At the very least, it would make foreach() with a > reference > > less > > of a problem: > > > > foreach ($array as let &$a) { > > $a =3D 3; > > } > > // $a is not in this scope - no need to worry about accidentally > > changing > > last array item > > > > Any thoughts? > > > > Hi, > > My 2 cents: That is a very minor improvement at the cost of an additional > keyword. It is only to avoid, that you accidentally interfere with outers > scope variables? If it is hard to track these variables, maybe your > method/function is too big. > > I agree. > Regarding your example: > > foreach ($array as &$a) { > $a =3D 3; > } > $a =3D null; // $a not a reference anymore. Problem solved :) > > Problem not solved. You have just changed the last element of $array... This is the exact problem that was to be avoided. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel > Regards, > Sebastian > > > > -- > > Andrea Faulds > > http://ajf.me/ > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > github.com/KingCrunch > --f46d041826a0dd87cb04f107c264--