Re: Compact can't resolve outer scoped variables using short closures
| From: | David Rodrigues | Date: | Thu, 20 Oct 2022 16:48:47 +0000 |
| Subject: | Re: Compact can't resolve outer scoped variables using short closures | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118860@lists.php.net to get a copy of this message | ||
> $foo = fn() => [$a, compact('a', 'b')];
> is essentially compiled to:
> $foo = function (use $a) { return [$a, compact('a', 'b')] };
Regarding this, in case you're literally saying that internally "fn()"
turns into a common "function", and getting back to the main topic, would
it be possible to do the same with compact()?
fn() => compact('dummy')
turns into:
fn() => [ 'dummy' => $dummy ]
which turns into:
function() use($dummy) { return [ 'dummy' => $dummy ]; }
Atenciosamente,
David Rodrigues