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