I think that introducing a new variable, that even uncommon, could cause BC.

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) ];
    };
}


Atenciosamente,
David Rodrigues


Em qua., 11 de nov. de 2020 às 14:59, Christoph M. Becker <cmbecke...@gmx.de>
escreveu:

> On 11.11.2020 at 18:39, Dan Ackroyd wrote:
>
> > On Tue, 10 Nov 2020 at 17:39, Hans Henrik Bergan <divinit...@gmail.com>
> wrote:
> >>
> >> something i'm missing from Javascript is the ability to give names to
> >> closures, ...the name is optional, and only visible inside the closure
> >> itself, and unfortunately this is not legal in PHP, i wish it was.
> >
> > I really like that...but unfortunately that wouldn't work in PHP.
> >
> > In JS, when a function is declared inside another function, the name
> > of it is limited to the scope of the containing function. In PHP, when
> > a function is declared inside another function, it is put into the
> > current namespace's global scope.
> >
> > Changing how scope works in PHP would be too large a change for just
> this.
>
> In JavaScript, a named function expression is different to a function
> declaration:
>
>     var fn = function foo() {console.log('blah')}
>     foo()
>     => Uncaught ReferenceError: foo is not defined
>
> vs.
>
>     function foo() {console.log('blah')}
>     foo()
>     => blah
>
> So the named function expression is still an anonymous function; the
> label is only defined inside of the function body.
>
> Christoph
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

Reply via email to