call_user_func_array.php

<?php

function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2\n" . '<br>';
}

class foo {
    function bar($arg, $arg2) {
        echo __METHOD__, " got $arg and $arg2\n" . '<br>';
    }
}

// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two"));

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

 

foobar got one and two 
foo::bar got three and four 

 

posted @ 2017-09-20 09:55  sky20080101  阅读(43)  评论(0)    收藏  举报