Created
November 20, 2017 21:26
-
-
Save pscheit/07c5e33822d251551c7571fa81e87b06 to your computer and use it in GitHub Desktop.
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 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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment