PHP call_user_func与只是调用函数 [英] PHP call_user_func vs. just calling function

查看:109
本文介绍了PHP call_user_func与只是调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这有一个非常简单的解释。这是什么区别:

 功能理发师($ type){
echo你想要一个$ type理发,没问题......;
}
call_user_func('barber',mushroom);
call_user_func('barber',shave);

...和这个(以及有什么好处?):

 功能理发师($ type){
echo您想要一个$型发型,没问题\ n;
}
barber('mushroom');
barber('shave');


解决方案

当您知道它时,始终使用实际的函数名称。

call_user_func 用于调用您不知道其名称的函数,但效率低得多该程序必须在运行时查找该功能。


I'm sure there's a very easy explanation for this. What is the difference between this:

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

... and this (and what are the benefits?):

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

解决方案

Always use the actual function name when you know it.

call_user_func is for calling functions whose name you don't know ahead of time but it is much less efficient since the program has to lookup the function at runtime.

这篇关于PHP call_user_func与只是调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆