Compact can't resolve outer scoped variables using short closures
| From: | David Rodrigues | Date: | Wed, 19 Oct 2022 17:04:15 +0000 |
| Subject: | Compact can't resolve outer scoped variables using short closures | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-118850@lists.php.net to get a copy of this message | ||
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.
Atenciosamente,
David Rodrigues