On Tuesday 23 February 2010 05:00:28 pm Ionut G. Stan wrote: > > 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).
IMO, globals could and should use a similar syntax to lexical closures: function foo($a, &$b) global ($c, &$d) { // ... } That would allow a parallel syntax, and allow for both by-value and by- reference globals, which currently we cannot do. And closures/lambdas could/should support the same syntax for globals. --Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php