Re: On closures and lamdba

From: Date: Tue, 23 Feb 2010 23:00:28 +0000
Subject: Re: On closures and lamdba
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-47039@lists.php.net to get a copy of this message
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/

« previous php.internals (#47039) next »