This is not entirely correct, you are right. There's a difference
between anonymous function and closure, though in practice in PHP
anonymous functions are closures (though some of them are rather trivial
ones with no variables to "close over") and that's now the only way to
do closure in PHP (i.e. you can't have non-anonymous closure function).

Correct me if I'm wrong, but given the fact that PHP only* supports functions defined in the global space**, with the additional ability to import global variables using the global statement, wouldn't that make named functions able to close-over global variables?

And, if the above is true, wouldn't it be consistent to support the use statement on named functions, and then deprecate the global statement?

I remember one of the first implementation for closure, used a statement similar to global for closing over variables (the lexical statement).

Thanks,

* I know it allows definition of function inside other functions, which will ultimately end up in the global scope.

** namespaced functions don't make any difference, as variables aren't namespaced.

--
Ionut G. Stan
I'm under construction  |  http://blog.igstan.ro/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to