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