Re: Compact can't resolve outer scoped variables using short closures

From: Date: Thu, 20 Oct 2022 06:31:06 +0000
Subject: Re: Compact can't resolve outer scoped variables using short closures
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-118855@lists.php.net to get a copy of this message
śr., 19 paź 2022 o 19:18 David Rodrigues <david.proweb@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

« previous php.internals (#118855) next »