Last active
September 5, 2015 05:52
-
-
Save sword-jin/44c8fcddd39fc4b55cf5 to your computer and use it in GitHub Desktop.
call_user_func_array()
笔记
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 | |
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 |
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 | |
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