php8.0使用elasticsearch8.8以后的版本报接口实现异常
1. 运行环境#
1). 当前使用的 Laravel 版本?#
9.52.16
2). 当前使用的 php 版本?#
PHP 版本:
8.0.28
3). 当前系统#
Windows 11
4). 业务环境#
开发环境
5). 相关软件版本#
Nginx,elasticsearch8.12.0
2. 问题描述?#
无法调用 es 包,比如
use Elastic\Elasticsearch\Response\Elasticsearch;
$es = new Elasticsearch();
dd($es);
报错如下:
In Elasticsearch.php line 87:
Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\
Http\Message\ResponseInterface must be compatible with Psr\Http\Message\ResponseInterface::withStatus($code, $reaso
nPhrase = <default>)
Fatal error: Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\Http\Message\ResponseInterface must be compatible with Psr\Http\Message\ResponseInterface::withStatus($code, $reasonPhrase = <default>) in D:\wwwroot\xyh-demo.com\vendor\elasticsearch\elasticsearch\src\Response\Elasticsearch.php on line 87
找到位置是 MessageResponseTrait
的 87 行,代码如下:
接口定义:
经过调试:
只有在实现方法里面去掉 $int
和 $code
的类型名才可以,在原生里面复原也没问题,找不到解决办法,只能将 es 退到了 8.0.0 版本是没问题的
此问题 php8.1 开始就是正常了,
使用 php8.0 的话,把包里面的接口通过自己定义的类实现也没问题。
不知道具体是什么原因引起的
有知道的朋友帮忙回复下,感谢
推荐文章: