PHP function missing argument error

前端 未结 5 456
孤街浪徒
孤街浪徒 2020-12-19 06:02

My validate function looks like that

function validate($data, $data2 = 0, $type)
{
...

Function call example

if ($result =          


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 06:23

    You should at least set the $type in this line:

    function validate($data, $data2 = 0, $type)
    

    at NULL or '' as you can see here:

    function validate($data, $data2 = 0, $type = null)
    

    PHP let you to set a value for the parameters, but you can't define a parameter WITHOUT a preset value AFTER parameter(s) which HAVE a preset value. So if you need to always specify the third param, you have to switch the second and the third like this:

    function validate($data, $type, $data2 = 0)
    

提交回复
热议问题