Re: Arrow function expressions in PHP
| From: | Nikita Nefedov | Date: | Thu, 01 Oct 2015 11:07:43 +0000 |
| Subject: | Re: Arrow function expressions in PHP | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88601@lists.php.net to get a copy of this message | ||
On Thu, 01 Oct 2015 13:48:52 +0300, Rowan Collins <rowan.collins@gmail.com> wrote:
Levi Morrison wrote on 01/10/2015 04:06:And yet we have super-globals. You can also access variables of one script's global scope from another script's global scope without importing or anything like that. I wouldn't say that PHP has or follows any idiomatic "way" of how scopes should work, it's just evolutionary.I'm going to ask everyone to stop saying that auto-closing is bad unless they also provide a demonstration of why it was bad.Please see my e-mail from last night, or Rasmus's in the original thread. It is "bad" (or, controversial) because it is a fundamental change to PHP's scoping rules, which currently treat all variables denoted by "$foo" as local to the current function, without exception.
I believe Levi's and Bob's intentions are not to introduce auto-capture but to add short closures, auto-capture being a tool that works best to help in achieving this.I'm also going to ask everyone to stop suggesting new syntax for importing variables. If use() is a pain then auto-importing the used variables is a good solution. If it's not a pain why are you suggesting new syntax?Because the feature is being described as "short closures", or as a new syntax, so people are looking for ways to make closures shorter without changing the functionality. If auto-capture is the main feature you are interested in, and syntax just a by-product, then it might be sensible to make that clear. As a straw man, it would be possible to have auto-capture closures with no new syntax at all, e.g. function($x) use(*) { return $x * $y; }
use(*) just as long as use($y), and the shorter version where you need to separate args from uses with semicolon will be harder to read (ex.: fn($x; $y) => $x * $y vs `fn($x) => $x * $y` - it's not obvious at all what semicolon does. Whereas with auto capture you can at least guess that this variable will be captured from defining scope, if you don't know how this feature works).