mixed call_user_func ( callable $callback
[, mixed $parameter
[, mixed $...
]] )
mixed call_user_func_array ( callable $callback
, array $param_arr
)
http://php.net/manual/en/function.call-user-func.php
http://php.net/manual/en/function.call-user-func-array.php
Foo.php
<?php
namespace Foobar;
class Foo {
public function bar($arg, $arg2) {
echo __METHOD__," got $arg and $arg2\n";
}
public static function test($name) {
printf("Hello, %s!\n", $name);
}
}
$foo = new Foo();
call_user_func_array([$foo, "bar"], ["three", "four"]);
call_user_func([$foo, "bar"], "three", "four");
call_user_func_array(function($arg1, $arg2) {
echo __FUNCTION__," got $arg1 and $arg2\n";
}, ["one", "two"]);
call_user_func_array(__NAMESPACE__.'\Foo::test', ['Hannes']);
call_user_func_array([__NAMESPACE__.'\Foo', 'test'], ['Philips']);
$ php Foo.php
Foobar\Foo::bar got three and four
Foobar\Foo::bar got three and four
Foobar\{closure} got one and two
Hello, Hannes!
Hello, Philips!