Re: RFC: Support Closures in constant expressions

From: Date: Mon, 04 Nov 2024 12:33:32 +0000
Subject: Re: RFC: Support Closures in constant expressions
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-125904@lists.php.net to get a copy of this message
On Mon, Nov 4, 2024, at 13:06, Tim Düsterhus wrote: > Hi > > Am 2024-10-31 07:16, schrieb Larry Garfield: > > Hm. It would never occur to me to use a function for a non-class > > constant in the first place, so I don't know. :-) Frankly I can't > > recall the last time I used a non-class constant period. :-) > > > > That said, PHP consts are already a bit squishy, and auto-capture is > > always by value. That wouldn't give us a loophole? > > Here's another brainteaser: > > function foo( > string $bar, > Closure $baz = static fn () => $bar, > ) { > var_dump($baz()); > } > > foo('captured'); > > What would you expect the semantics of that script to be? Isn't this semantically equivalent to: function foo( string $bar, Closure $baz, ) { $baz = static fn () => $bar; var_dump($baz()); } foo('captured'); — Rob

« previous php.internals (#125904) next »