call_user_func和call_user_func_array正确打开方式

<?php
function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2\n";
}
class foo {
    function bar($arg, $arg2) {
        echo __METHOD__, " got $arg and $arg2\n";
    }
}


// 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"));
//如果在框架中$foo,可替换为$this指明所在的类
  • call_user_func和call_user_func_array区别
    第一个参数都是回调函数,第二个参数一个为mixed类型,一个为array类型
posted @ 2022-02-24 14:26  小刘的早餐店  阅读(21)  评论(0编辑  收藏  举报