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