Re: [RFC] Draft - Closure self reference

From: Date: Fri, 20 Nov 2020 15:14:41 +0000
Subject: Re: [RFC] Draft - Closure self reference
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-112261@lists.php.net to get a copy of this message
On Wed, Nov 11, 2020 at 12:37 PM David Rodrigues <david.proweb@gmail.com> wrote: > My suggestion is to reuse the keyword as to set a variable that > will > represent its own closure. It is more flexible once that we could choose > any name and reuse in nested closures. It is pretty similar to how SQL > works too. > > function fn1() as $lambda1 { > return function() as $lambda2 use ($lambda1) { > return [ gettype($lambda1), gettype($lambda2) ]; > }; > } > > My initial reaction to this is: Technically doable (easy even), but looks a bit... ugly? weird? surprising? I think my main objection to it is how much is now stacked after the parameter list: function($args...) : returnType as $local use ($captures...) { ... }; That's a lot of... stuff (granted, we have most of it already) and how it looks when stacked together gets funky. Is it returnType as $thing ? That doesn't read well, but I don't see us making return type movable. as/use should be placable in either order, but maybe we give them required order anyway? TLDR; Long winded way to say I'm not inherently against this, and I like the idea of a lambda being able to recurse (not that I can ever recall having use for it, but maybe I fell back on named functions for that), I just think it's getting a bit wordy. -Sara

« previous php.internals (#112261) next »