call_user_func()
또는 call_user_func_array
PHP 방법을 권장합니다 . 여기서 확인할 수 있습니다 ( call_user_func_array , call_user_func ).
예
class Foo {
static public function test() {
print "Hello world!\n";
}
}
call_user_func('Foo::test');//FOO is the class, test is the method both separated by ::
//or
call_user_func(array('Foo', 'test'));//alternatively you can pass the class and method as an array
메소드에 전달할 인수가 있으면 call_user_func_array()
함수 를 사용하십시오 .
예.
class foo {
function bar($arg, $arg2) {
echo __METHOD__, " got $arg and $arg2\n";
}
}
// Call the $foo->bar() method with 2 arguments
call_user_func_array(array("foo", "bar"), array("three", "four"));
//or
//FOO is the class, bar is the method both separated by ::
call_user_func_array("foo::bar"), array("three", "four"));