Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41047 invoked from network); 31 Jan 2017 21:27:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 21:27:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.68 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.68 mail-wm0-f68.google.com Received: from [74.125.82.68] ([74.125.82.68:32891] helo=mail-wm0-f68.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/6C-51557-35101985 for ; Tue, 31 Jan 2017 16:27:48 -0500 Received: by mail-wm0-f68.google.com with SMTP id v77so1064816wmv.0 for ; Tue, 31 Jan 2017 13:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=vyWB0U8E2aX/7ShHg5XbA1eMuFzN62PSqtwQdu8p44U=; b=nCfB+wqdCiQ+3xSk8m9jiZXj86EC9Ixn3YDPhEn275mrnDFOQrMSJYTCUK4wu/zvPo 2id44PtwZsBr2BMaRQsLNxhUFPById1jCIh4r0mx6mf3cE9PQtCScGEnHRD4KgPNr1+2 gRKkFBHKTj1zq/wRG7ycjqBeeOpC/ARa936e5OA/BUt8U/yHoY7m8Uwd0UqPfNkpIQLt hIUhHS20v5unuAo6/Z3roYHti3HQH+DDS1F84f+RyFmcw86Ha0OGFk3LfI2Wa0WgiaW6 i0lHXrPPHmv7yScv3cOT+mg+DtXVnjK7h4mj0VZtgMY0rn9bunexR1gr6c4f0D/DdjnX yMog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=vyWB0U8E2aX/7ShHg5XbA1eMuFzN62PSqtwQdu8p44U=; b=TFWtYjzJ3OsZhiWhAZgaSo+BDSLX1eXp7xTKbt0xnJijxu5cGMABm23DQKusx3HpBF p9XBPlC/PUh4z2AFoOxDyklQYAGQxsRi5U9/MR+en2w9chR3mNe8rkYTwu170uLcLssJ 080maXp9MHe59a5nN7ZbVfzmGc6lfRoH6WBCFKvSDFynFNRsFZjMSUrOSk9EMR1hxmBn VaTIrDAfgFuGjTlxixEu+tJ44RKV0J3xTJ2g9tGL5nX/k2zEszyWIfSYoM+BGZHwMUHA gzqzjuboVvwH8H+eVDLXr9L9mxSHxBSqWGA8eS5FSAt9NNRBxY6UJyWpdIyNIvOUukea 1EoQ== X-Gm-Message-State: AIkVDXK8zYaRzTePMIwC85dW1N4Wz+TicjhxpcbAEX33Hhg0oVtajB5FGAUbilcKa0ziIA== X-Received: by 10.28.148.76 with SMTP id w73mr21020494wmd.43.1485898064729; Tue, 31 Jan 2017 13:27:44 -0800 (PST) Received: from ?IPv6:2a00:23c4:4bd2:6e00:a92d:54e0:595b:1fb? ([2a00:23c4:4bd2:6e00:a92d:54e0:595b:1fb]) by smtp.googlemail.com with ESMTPSA id l67sm25824336wmf.1.2017.01.31.13.27.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jan 2017 13:27:43 -0800 (PST) To: internals@lists.php.net References: <1E.BA.51557.966F0985@pb1.pair.com> Message-ID: Date: Tue, 31 Jan 2017 21:27:40 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <1E.BA.51557.966F0985@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: [RFC][Discuss] Arrow Functions From: rowan.collins@gmail.com (Rowan Collins) On 31/01/2017 20:41, Andrea Faulds wrote: > That's the idea. I'd prefer it if auto-capture was not restricted to > single-expression functions (“arrow functions”). Though arrow > functions make most sense with auto-capture, it doesn't need to be > stricted to them. I respectfully disagree completely. Variable scope in PHP is very simple: inside a function, all variables are local to that function, and fetching them from anywhere else requires them to be enumerated with a specific keyword (e.g. global, static, use). The only exceptions are superglobals, the magic $this, and the odd mysterious materialisation like $http_response_header [1]. This means you can look at a function in isolation, no matter how it's declared, and see where every variable comes from. [1]: http://php.net/manual/en/reserved.variables.httpresponseheader.php Auto-capture with a full function body would be throwing out that principle. If a variable was read from before it was assigned to, that *might* mean it was unset, or it *might* mean it was imported from an outer scope. Changing the variable name in the outer scope might or might not require you to look for that variable name in the closure; adding a variable in the outer scope might *accidentally* change the behaviour of the closure; and so on. This is a lot easier in Javascript, although still a cause of confusion, because you can carry on until you hit "var" or "let". I understand C# also has auto-importing closures, but it too requires variables to be declared at some point. Initially, I was sceptical of auto-capture even with a single expression, but I've come round to its usefulness in short closures. Limiting it to a single expression ensures it's short, and means you can assume that *all* variables in the expression are imported other than those listed as parameters. Just an opinion, obviously, but I'm glad that the current proposal is limited to and optimised for this single expression case. Regards, -- Rowan Collins [IMSoP]