Re: Compact can't resolve outer scoped variables using short closures
| From: | Marco Pivetta | Date: | Wed, 19 Oct 2022 17:08:47 +0000 |
| Subject: | Re: Compact can't resolve outer scoped variables using short closures | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118851@lists.php.net to get a copy of this message | ||
On Wed, 19 Oct 2022, 19:04 David Rodrigues, <david.proweb@gmail.com> wrote:
> Hello!
>
> I'm converting my code to use short closures where possible, and I ran into
> a problem using compact().
>
> Basically, the names used in compact() cannot be accessed due to a bug,
> reported in 2019 still in PHP 7.4 (ID 78970).
>
> https://bugs.php.net/bug.php?id=78970
>
> It seems to me to be a reasonable problem and one that needs attention, as
> the message is not that "compact cannot be used here", but that "the
> variable does not exist".
>
> The code below may reproduce the problem:
>
> $x = 123;
> (fn() => compact('x'))();
>
> https://3v4l.org/AFARs
>
> Is there any possibility of this being fixed? I would love to help, but I
> don't have much C programming skills, unfortunately.
>
I'd rather hope for
compact() to finally be deprecated and targeted for
removal 😛
The fact that it still exists precludes (or at least complicates) future
optimization of scope + inlining in the engine.
Similar thoughts towards extract(), I'd say.