Skip to content

Instantly share code, notes, and snippets.

@dogmatic69
Created February 2, 2016 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogmatic69/a32490e70a4d191909d8 to your computer and use it in GitHub Desktop.
Save dogmatic69/a32490e70a4d191909d8 to your computer and use it in GitHub Desktop.
make calling shitty methods with too many parameters much better.
<?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