drqyxkzbs21968684 2019-07-05 19:42
浏览 63
已采纳

将多个Vars传递给PHP函数

I have an issue passing a variable to a PHP function. I'm running a Raspberry Pi webserver with PHP 7.0.33. Everything runs fine on the raspberry. When I upload my pages to my Godaddy server which is running PHP 7.2 I get the dreaded white page of death. I traced it down to the following. This is simplified.

On the raspberry:

This is how I'm sending the variables.

updateCustomer($uniqueid, $name, $title);  

This is how I receive them in the function.

function updateCustomer($uniqueid, $name, $title, $job){
}

On the raspberry I send 3 vars ($uniqueid, $name, $title). The function is looking for 4 vars ($uniqueid, $name, $title, $job) but ignores the last one ($job) if it doesn't exist.

This will not work on the Godaddy server unless I send 4 vars and receive 4 vars. So for testing I just plugged in $x like this and it works.

function updateCustomer($uniqueid, $name, $title, $x){
}

So my question...Is this a function difference between PHP 7.033 and the 7.2 that's running on Godaddy? Or is there a setting within the PHP setup that would allow this to work?

  • 写回答

2条回答 默认 最新

  • duanba8173 2019-07-05 19:57
    关注

    Yes, there was a change between PHP 7.0 and PHP 7.1.

    Previously (PHP <=7.0), a warning would be emitted for invoking user-defined functions with too few arguments. Now (PHP >=7.1), this warning has been promoted to an Error exception. This change only applies to user-defined functions, not internal functions.

    Which is what you're seeing in effect - it was changed from a warning (so it works, no errors - just a message), to an actual error.

    The solution is to simply fix it, by adding a default value to the parameter, thereby making it optional.

    function updateCustomer($uniqueid, $name, $title, $job = null) {
       // ..
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab