Function object: Difference between revisions

Content deleted Content added
In PowerShell: the use of $script: does not appear intended -- it would make $a and $b share state and is unnecessary with the use of .GetNewClosure()
m In PHP: PHP-FIG PSR
Line 572:
 
<source lang=PHP>
function Accumulator( $start ) {
$current = $start;
return function( $x ) use( &$current ) {
return $current += $x;
};
}
</source>
Line 585:
$a = Accumulator(4);
$x = $a(5);
echo "x = $x<br/>"; // x = 9
$x = $a(2);
echo "x = $x<br/>"; // x = 11
</source>