自过去两天以来,我面临着非常奇怪的问题,我有两个不同的服务器,一个是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/