Created
February 2, 2016 10:24
-
-
Save dogmatic69/a32490e70a4d191909d8 to your computer and use it in GitHub Desktop.
make calling shitty methods with too many parameters much better.
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 Foo { | |
function bar($a, $b, $c) { | |
echo '$a - $b - $c :: ' . implode(' - ', func_get_args()); | |
} | |
} | |
function angular($callable, $args) { | |
$reflection = new ReflectionMethod($callable[0], $callable[1]); | |
$params = array(); | |
foreach ($reflection->getParameters() as $k => $v) { | |
$params[] = $v->name; | |
} | |
call_user_func_array($callable, array_merge( | |
array_fill_keys($params, null), | |
$args | |
)); | |
} | |
$callable = array(new Foo, 'bar'); | |
angular($callable, array( | |
'c' => 'ccc', | |
'a' => 'aaa', | |
'b' => 'bbb', | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment