Can I use a function to return a default param in php?

后端 未结 4 976
予麋鹿
予麋鹿 2021-01-22 21:07

I would like to do something like this:

function readUser($aUser = loadDefaultUser()){

 //doing read User
}

I find that it will display a erro

4条回答
  •  孤城傲影
    2021-01-22 21:13

    I would rather give a Null value for this argument and then call loadDefaultUser() in the body of the function. Something like this:

    function readUser($aUser = NULL){
        if(is_null($aUser)){
            $aUser = loadDefaultUser();
        }
        //...
    }
    

提交回复
热议问题