
在 php 中使用 __callstatic() 无法获取参数?
问题描述
在使用 thinkphp 时,validate 验证始终失败,定位到如下问题:
public static function __callStatic($method, $params)
{
var_dump($params);exit;
$class = self::make();
if (method_exists($class, $method)) {
return call_user_func_array([$class, $method], $params);
} else {
throw new \BadMethodCallException('method not exists:' . __CLASS__ . '->' . $method);
}
}在本地 php 7.4.28 环境中,$params 可以成功获取参数,但在生产环境 php 7.3.0 中,$params 却为空,导致验证失败。
立即学习“PHP免费学习笔记(深入)”;
答案
这个问题是 php 7.3.0 的一个已知错误,并在 php 7.3.2 中被修复。
php bug 报告 #77339 描述了这个问题:__callstatic 可能会获取不正确的参数。
在 php 7.3.0 中,__callstatic 方法无法正确处理 class 方法的参数,导致 $params 为空。
解决方案
要解决这个问题,请升级到 php 7.3.2 或更高版本。
以上就是PHP7.3.0下__callStatic()方法参数丢失问题:如何解决Validate验证失败?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号