php call_user_func() 函数

例1:

function barber($type){
    echo "you wanted a $type haircut, no problem\n";
}
call_user_func('barber','mushroom');

返回:
you wanted a mushroom haircut, no problem

例2:

class myclass{
    static function say_hello(){
        echo "hello!\n";
    }
}

call_user_func(['myclass', 'say_hello']);

call_user_func("myclass::say_hello");

call_user_func([new myclass(), 'say_hello']);

猜你喜欢

转载自www.cnblogs.com/double330/p/12803277.html