Re: Compact can't resolve outer scoped variables usingshort closures
| From: | Christoph M. Becker | Date: | Thu, 20 Oct 2022 17:23:30 +0000 |
| Subject: | Re: Compact can't resolve outer scoped variables usingshort closures | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118863@lists.php.net to get a copy of this message | ||
On 20.10.2022 at 19:03, Rowan Tommins wrote:
> On 20/10/2022 17:48, David Rodrigues wrote:
>
>> 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 ]; }
>
> Yes, that is what I meant by "it would be possible for the compiler to
> special-case this scenario";
Well, in the general case, the compiler cannot special-case this,
because compact() is a normal function, so might be used as "variable
function", or may not refer to the top-level compact() at all (the
called symbol may not be fully qualified).
> I explained why I think that would be a bad
> idea, and suggested an alternative.
ACK
--
Christoph M. Becker