PHP function

Last Updated: August 14, 2021

call_user_func_array()

You can use the call_user_func_array function in PHP to call a function and method call of a PHP class

Calling a function of PHP

function simmplefn($arg, $arg2) {
    echo " got $arg and $arg2\n";
}
// Call the simmplefn() function with 2 arguments
call_user_func_array("simmplefn", array("one", "two"));

Calling a method of a PHP Class

class Test {
    function simmplefn($arg, $arg2) {
        echo " got $arg and $arg2\n";
    }
}

// Call the $t->simmplefn() method with 2 arguments
$foo = new foo;
call_user_func_array(array($t, "simmplefn"), array("three", "four"));