śr., 19 paź 2022 o 19:18 David Rodrigues <david.pro...@gmail.com>
napisał(a):

> > I'd rather hope for `compact()` to finally be deprecated and targeted for
> removal 😛
>
> I think compact() is a good function for transferring variables from one
> point to another, but I would think about making improvements as it is
> confusing (uses the variable name, rather than the variable itself).
>
> Regarding the bug, if we use an array it should work perfectly:
>
> $x = 123;
> (fn() => [ 'x' => $x ])();
>
> https://3v4l.org/ov7TM
>
> Would it be possible to automatically convert compact() to an array at
> runtime? So I imagine that any necessary optimization can take place
> directly over the resulting array, rather than the compact itself.
>

How would you like it to work, if you pass a variable name variable to
compact then?
$x = 123;
$name = 'x';
(fn () => compact($name))();

I agree with the idea of deprecating compact() & extract() and in
long-term variable of variables as well.

Cheers,
Michał Marcin Brzuchalski

Reply via email to