Re: Arrow function expressions in PHP

From: Date: Wed, 30 Sep 2015 16:19:34 +0000
Subject: Re: Arrow function expressions in PHP
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-88582@lists.php.net to get a copy of this message
Marcio Almada wrote on 30/09/2015 15:49:
That's not to say that automatic capture is an absolute blocker, but I think
"the internals community is divided on it" is a reasonable summary. That's the part I couldn't comprehend in the discussion. Auto import is basically the most interesting reason to have short closures on PHP.
It's also the biggest departure from existing PHP semantics - PHP's scoping rules are remarkably simple compared to other languages: everything is local unless qualified. No scope chains like JS, no "my" and "our" like Perl, no short-hand references to properties of "this" like Java, etc. "use", "global", and "static" can all be seen as explicitly importing variables into that local scope. Breaking that rule is something that needs to be considered very carefully, and is a lot more than a minor detail of syntax. I note that C++11, although it has a very compact (and keyword-less) lambda syntax, still requires an explicit list of captured variables; unfortunately, we can't just copy that syntax either, because we've used [$var] for array construction. But it does show that "short closures" and "auto-capture closures" are two different features; we could save up to 17 characters without changing behaviour if we could eliminate the keywords "function", "use", and "return". Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#88582) next »