Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105963 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74479 invoked from network); 17 Jun 2019 20:36:12 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 17 Jun 2019 20:36:12 -0000 To: internals@lists.php.net References: Date: Mon, 17 Jun 2019 18:50:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Posted-By: 94.1.167.52 Subject: Re: [PHP-DEV][RFC] Alternative "use" syntax for Closures From: markyr@gmail.com (Mark Randall) Message-ID: 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