Re: Brainstorming idea: inline syntax for lexical (captured) variables
| From: | Alexandru Pătrănescu | Date: | Wed, 15 Mar 2023 03:28:39 +0000 |
| Subject: | Re: Brainstorming idea: inline syntax for lexical (captured) variables | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119704@lists.php.net to get a copy of this message | ||
On Wed, Mar 15, 2023 at 1:09 AM Rowan Tommins <rowan.collins@gmail.com>
wrote:
> On 14/03/2023 22:54, Larry Garfield wrote:
>
> Well, a large part of my resistance to automatic capture is that it
> makes variable scope less visible at a glance. This avoids that by still
> having a marker for "I am from another scope", but a much less verbose
> one than the current use() clause.
>
How about first implementing use() for anonymous classes first?
Something like:
function foo(int $outer) {
return new class() use($outer) {
public function getIt() {
return $outer;
}
};
}
This would help with the main problem you expressed and be a less concern
for the future.
It's a different direction from what you suggested but it might be a lot
harder to pass a $^ syntax or similar.
Regards,
Alex