PHP的call_user_func可以帶入函式名稱和參數並執行

執行ask function並代入name參數

function ask($name) {
    echo "Your name is $name" . PHP_EOL;
}
call_user_func('ask', "Johnson");
call_user_func('ask', "Maple");

使用匿名函式執行init程式

call_user_func(
    function() {
        //initialize code
        set_include_path(implode(PATH_SEPARATOR, array(
            realpath('/framework/library'),
            realpath(__DIR__ . '/src'),
            realpath(__DIR__ . '/lib'),
            get_include_path(),
        )));
    }
);
Categories: PHP