php - PHP ArgumentCountError 服务器特定吗?

标签 php parameter-passing

自过去两天以来,我面临着非常奇怪的问题,我有两个不同的服务器,一个是Windows(php v5.3),第二个是linux(php v7.1 ngnix)。我有一个项目(由某人编写)已经在 Windows 服务器上运行,现在我必须将该项目移到 Linux 服务器上(无需更改代码)。我的问题,有一个登录功能 -

Function userAuthentication($username,$password,$locationId,$url,$source)
{
....
}

它正在调用(在 Windows 服务器上)

userAuthentication($username, $password,'',$url) ;

我知道在这种情况下参数不匹配,但正如我测试的那样,这段代码实际上给了我结果并且在 Windows 上工作正常,但相同的代码在 Linux 服务器上给了我明显的错误 -

ArgumentCountError: Too few arguments to function Authentication::userAuthentication(), 4 passed in

它可以通过更改该代码来解决,但我不希望(可以是许多具有相同错误的函数)。 我已经用谷歌搜索但没有找到任何东西。我很好奇为什么 Windows 上没有发生这种情况。是ArgumentCountError服务器特定的还是Windows服务器不认为它像linux一样重要,或者php版本问题或任何其他配置?我想解决什么问题才能解决这个问题?

任何人对此有任何想法,请帮助我,谢谢

最佳答案

区别不在于环境(Windows 与 Linux),而在于 PHP 版本。

正如您在从 PHP 7.0 到 7.1 的迁移中所看到的(链接: http://php.net/manual/en/migration71.incompatible.php )

传递过少的函数参数时抛出

Previously, a warning would be emitted for invoking user-defined functions with too few arguments. Now, this warning has been promoted to an Error exception. This change only applies to user-defined functions, not internal functions. For example:

<?php
function test($param){}
test();

上面的示例将输出类似的内容:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function test(), 0 passed in %s on line %d and exactly 1 expected in %s:%d

如何解决?

您必须定义函数中的所有参数。这可能会“不舒服”,但作为开发人员,这是更好的做法。在这个问题上不要偷懒。

关于php - PHP ArgumentCountError 服务器特定吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47260756/

相关文章:

c - 为什么我们在传递二维数组作为参数时需要指定列大小?

c# - DLLImport:传递短类型参数

c++ - C++ 中返回简单哈希码的函数

javascript - 需要帮助确定如何在 mediawiki 中编辑 div

php - 两个数组中的数组交集部分匹配

java - 识别一个字符是中文并从简体字得到中文 "pinyin"拼音?

python - 区分 "fundamental"ctypes 数据类型及其子类?

c++ - 将类的所有变量传递给函数

php - 如何在codeigniter中使用参数为url创建分页?

php - 如何创建一个方法,就像我在 php 中所做的那样,但在 Objective-C 中