Created
November 20, 2017 21:26
-
-
Save pscheit/07c5e33822d251551c7571fa81e87b06 to your computer and use it in GitHub Desktop.
Revisions
-
pscheit created this gist
Nov 20, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ <?php class Closures { public static function create($methodName) { return function($thing) use ($methodName) { return $thing->{$methodName}(); }; } } class Thing { public function __construct($value) { $this->value = $value; } public function getSomething() { return $this->value; } } $things = [new Thing(1), new Thing(2), new Thing (3)]; print_r(array_map(Closures::create('getSomething'), $things));