使用的版本是
"topthink/think-validate": "^2.0"
class MemberValidate extends Validate
{
protected $rule = [
'name' => 'require|length:3,25',
'password' => 'require|length:8,16',
'email' => 'require|email'
];
protected $message = [
'name.require' => '名称不能为空',
'name.length' => '名称长度在3-25个字符',
'password.require' => '密码不能为空',
'password.length' => '密码长度在8-16个字符',
'email' => '请输入有效的邮箱地址'
];
protected $scene = [
'register' => ['name','password','email'],
'login' => ['password','email']
];
}
$validate = new MemberValidate();
//$rs = $validate->check($data); //这样是正常的,下面加场景验证就报错。
$rs = $validate->scene('login')->check($data);
报错信息如下:
filter_var(): Argument #3 ($options) must be of type array|int, null given
看起来是 topthink/think-validate 这个项目不支持php8
试试我修改过的这个
https://github.com/yzh52521/webman-validate