为什么当我将太多参数传递给函数时,PHP不会抛出错误? [英] Why does PHP not throw an error when I pass too many parameters to a function?

查看:184
本文介绍了为什么当我将太多参数传递给函数时,PHP不会抛出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php的n00b。

 函数doFoo($ name =johnny){
回显Hello $ name。 < br />;
}

我拨打了这些电话

  doFoo(); 
doFoo(ted);
doFoo(ted,22);

前两个输出了预期的结果,即

 您好johnny 
您好特德

但是第三次电话还打印了

 您好特权

我希望有一个错误,毕竟函数是为一个参数创建的,而我用两个参数调用它。

为什么没有错误?

解决方案

PHP不会在函数过载中引发错误。

I am a n00b at php. I was learning about Default Parameters so I made this function.

function doFoo($name = "johnny"){
    echo "Hello $name" . "<br />";
}

I made these calls

doFoo();  
doFoo("ted");  
doFoo("ted", 22); 

The first two printed what was expected i.e

Hello johnny  
Hello ted

but the third call also printed

Hello ted 

I was expecting an error, after all the function is made for one argument whereas I am calling it with two arguments.
Why was there no error?

解决方案

PHP doesn't throw an error on function overload.

这篇关于为什么当我将太多参数传递给函数时,PHP不会抛出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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