Skip to content

Instantly share code, notes, and snippets.

@rcstr
Created September 28, 2013 04:08
Show Gist options
  • Save rcstr/6738272 to your computer and use it in GitHub Desktop.
Save rcstr/6738272 to your computer and use it in GitHub Desktop.
Ejemplo basico de closures en PHP 5.4
<?php
class Calc {
public function mult($by = 1) {
return function($number) use($by) {
return $by * $number;
};
}
}
$calc = new Calc;
$multBy10 = $calc->mult(10);
echo $multBy10(5); // 50
$multBy34 = $calc->mult(34);
echo $multBy34(8); // 272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment