PHP函数缺少参数错误 [英] PHP function missing argument error
问题描述
函数validate($ data,$ data2 = 0,$ type)
{
...
函数调用示例
if($ result = validate($ lname,'name')!== true)
response(0,$ result,'lname');
正如您所见,我的验证函数有3个输入变量。我没有经常使用第二个var - $ data2,这就是为什么默认设置为0的原因。但是,当我调用这个函数作为给定的例子(据我所知,这意味着$ data = $ lname,$ data2 = 0,$ type ='name')得到错误信息
对于validate()缺少参数3($ type)
我该如何解决这个问题?
验证失败的参数3($ type) b
总是列出可选参数作为最后一个参数。由于PHP没有命名参数,也没有重载ala Java,这是唯一的方法:
pre $ function validate($ data, $ type,$ data2 = 0){
}
My validate function looks like that
function validate($data, $data2 = 0, $type)
{
...
Function call example
if ($result = validate($lname, 'name') !== true)
response(0, $result, 'lname');
As you see, my validate function has 3 input vars. I'm not using second var - $data2 often, that's why set it to 0 by default. But when I'm calling this function as given example (as far as I know it means $data=$lname, $data2=0, $type='name') getting error message
Missing argument 3 ($type) for validate()
How can I fix that?
Missing argument 3 ($type) for validate()
Always list optional arguments as the last arguments. Since PHP doesn't have named parameters nor "overloading ala Java", that's the only way:
function validate($data, $type, $data2 = 0) {
}
这篇关于PHP函数缺少参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!