Skip to content

Instantly share code, notes, and snippets.

@sword-jin
Last active September 5, 2015 05:52
Show Gist options
  • Save sword-jin/44c8fcddd39fc4b55cf5 to your computer and use it in GitHub Desktop.
Save sword-jin/44c8fcddd39fc4b55cf5 to your computer and use it in GitHub Desktop.
call_user_func_array() 笔记
<?php
function foobar($arg1, $arg2)
{
echo __FUNCTION__ . " got $arg1 and $arg2\n";
}
class foo
{
function bar($arg1, $arg2)
{
echo __METHOD__ . " got $arg1 and $arg2\n";
}
}
call_user_func_array('foobar', ['one', 'tow']); // foobar got one and tow
$foo = new foo;
call_user_func_array([$foo, 'bar'], ['one', 'two']); // foo::bar got one and two
<?php
namespace App;
class Foo
{
public static function test($name)
{
print "Hello {$name}!\n";
}
}
call_user_func_array([__NAMESPACE__ . '\Foo', 'test'], ['rrylee']);
call_user_func_array(__NAMESPACE__ . '\Foo::test', ['rrylee']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment