Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-20 Thread Rowan Tommins
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' =>

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-20 Thread David Rodrigues
> $foo = fn() => [$a, compact('a', 'b')]; > is essentially compiled to: > $foo = function (use $a) { return [$a, compact('a', 'b')] }; 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

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-20 Thread Rowan Tommins
On 19/10/2022 18:04, David Rodrigues wrote: 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". I'd just like to point out that the error message here is 100% correct: there

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-20 Thread Claude Pache
> > How would you like it to work, if you pass a variable name variable to > compact then? > $x = 123; > $name = 'x'; > (fn () => compact($name))(); > Although it is difficult to make it work in general (of course), there is the specific case of names given as literal strings, as in the

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-20 Thread Michał Marcin Brzuchalski
śr., 19 paź 2022 o 19:18 David Rodrigues 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 >

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-19 Thread David Rodrigues
> 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

Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-19 Thread Marco Pivetta
On Wed, 19 Oct 2022, 19:04 David Rodrigues, 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). > >

[PHP-DEV] Compact can't resolve outer scoped variables using short closures

2022-10-19 Thread David Rodrigues
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