webman:captcha库报错
一,报错代码:
// 验证码长度
$length = 4;
// 包含哪些字符
$chars = '0123456789abcefghijklmnopqrstuvwxyz';
$builder = new PhraseBuilder($length, $chars);
$captcha = new CaptchaBuilder(null, $builder);
// 生成验证码
$captcha->build($width = 200, $height = 80, $font = null);
// 将验证码的值存储到session中
$request->session()->set('captcha', strtolower($captcha->getPhrase()));
// 获得验证码图片二进制数据
$img_content = $captcha->get();
return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
报错信息:
ErrorException: Webman\Captcha\CaptchaBuilder::__construct(): Implicitly marking
parameter $builder as nullable is deprecated, the explicit nullable type must be used
instead in /web/vendor/webman/captcha/src/CaptchaBuilder.php:143
Stack trace:
问题原因:
php8不允许直接使用null作为参数,
二,解决:
修改:
/web/vendor/webman/captcha/src/CaptchaBuilder.php:143
内容:
public function __construct($phrase = null, ?PhraseBuilderInterface $builder = null)
说明:在此一行增加了一个?
这个有更好的解决方法吗?请大家提供一下