Skip to content

Instantly share code, notes, and snippets.

@pscheit
Created November 20, 2017 21:26
Show Gist options
  • Save pscheit/07c5e33822d251551c7571fa81e87b06 to your computer and use it in GitHub Desktop.
Save pscheit/07c5e33822d251551c7571fa81e87b06 to your computer and use it in GitHub Desktop.
<?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