Re: [RFC] Alternative "use" syntax for Closures
| From: | Mark Randall | Date: | Mon, 17 Jun 2019 17:50:25 +0000 |
| Subject: | Re: [RFC] Alternative "use" syntax for Closures | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105963@lists.php.net to get a copy of this message | ||
On 17/06/2019 15:40, Ben Ramsey wrote:
Where "use (...)" would auto-capture all of the used variables in a similar manner to short closures, that would certainly save a bit of time.
Would this mean that all variables in the “parent" are now available in the “child?” This seems like it could result in some unexpected surprises as scope “leaks” across these boundaries.Just the ones which are used, like short closures. $x = 0; $y = 1; $z = 2; $closure = function($value) use (...) { $result = $x * $y * $value; if (something($result)) {
return $result;} return -1; }; $x and $y would be captured, $z would not be. I believe this is how short closures are implemented, but is at present only supporting a single line. -- Mark Randall