Re: Brainstorming idea: inline syntax for lexical (captured) variables

From: Date: Wed, 15 Mar 2023 18:16:32 +0000
Subject: Re: Brainstorming idea: inline syntax for lexical (captured) variables
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-119715@lists.php.net to get a copy of this message
On Tue, Mar 14, 2023, at 10:28 PM, Alexandru Pătrănescu wrote: > 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 For the record, while the auto-capture RFC[1] didn't reach a 2/3 majority to pass, it did have a strong majority support (62%). Given that, I think it unlikely that a "require verbose manual capture in more places" proposal would fair that well. [1] https://wiki.php.net/rfc/auto-capture-closure --Larry Garfield

« previous php.internals (#119715) next »