closures

php closures and lambda functions rfc

There is a discussion going on in php land about introducing closures and lambda functions, there was even a discussion on haskell-cafe about it (chx strikes again ;). About time, I would say. Having this functionality is a bonus. Having it implemented badly or half-arsed is going to do more damage than help. This is a short summary of what do I understand from the rfc and what do I think about it.

Closure

Intent
Close over the free variables of a function. Save the state for future use.
Motivation
We want to maintain the history of computation, an maybe save and reuse the computation
Implementation
php 5.3 implements anonymous functions, albeit verbously, with explicit declaration of variables to close over
Example

$y = ...;
x = function() use ($y){
   ....
}
Note
In some sense, closures and objects are dual, compare behaviour with state and state with behaviour
Yet another note:
Alternatively have a look at this implementation or my emulating closures in php blurb
Powered by Drupal, an open source content management system