(PHP 4, PHP 5, PHP 7, PHP 8)
call_user_func — Call the callback given by the first parameter
ExamplesExample #2 call_user_func() example
<?php
function barber($type)
{
echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>
The above example will output:
You wanted a mushroom haircut, no problem You wanted a shave haircut, no problem
Example #3 call_user_func() using namespace name
<?phpnamespace Foobar;
class
Foo {
static public function test() {
print "Hello world!\n";
}
}call_user_func(__NAMESPACE__ .'\Foo::test');
call_user_func(array(__NAMESPACE__ .'\Foo', 'test'));?>
The above example will output:
Hello world! Hello world!
Example #4 Using a class method with call_user_func()
<?phpclass myclass {
static function say_hello()
{
echo "Hello!\n";
}
}$classname = "myclass";call_user_func(array($classname, 'say_hello'));
call_user_func($classname .'::say_hello');$myobject = new myclass();call_user_func(array($myobject, 'say_hello'));?>
The above example will output:
Example #5 Using lambda function with call_user_func()
<?php
call_user_func(function($arg) { print "[$arg]\n"; }, 'test');
?>
The above example will output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4