Created
September 28, 2013 04:08
-
-
Save rcstr/6738272 to your computer and use it in GitHub Desktop.
Ejemplo basico de closures en PHP 5.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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