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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to