天天看点

使用EasyChat时报错:Symfony 和 Psr的 dispatch冲突了

Declaration of Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch(Symfony\Contracts\EventDispatcher\object $event, string $eventName = NULL) must be compatible with Psr\EventDispatcher\EventDispatcherInterface::dispatch(Psr\EventDispatcher\object $event)

报错什么意思?

Symfony 和 Psr的 dispatch冲突了

报错环境:

php: 7.0.10

fastadmin: thinkphp5.0.24 + bootstrap后台框架

EasyChat: "overtrue/wechat": "~4.2"

报错位置:

使用EasyChat时报错:Factory::openWork($providerConfig)

解决问题:

更换PHP的版本:换成 PHP7.3 不再报错

-------------------------------------------------------记录解决问题的过程,有兴趣可看下-------------------------------------------------------

1.因为是使用EasyChat时报的错误,所以首先找到EasyChat的官网。官网也是这样使用的Factory::openWork($config)

2.使用没有问题,难道是EasyChat的版本问题。然后找到项目下的conposer.json,发现用的是"overtrue/wechat": "~4.2",好像也没什么问题

3.然后,看到conposer.json文件,thinkphp5.0.24要求PHP5.6,接着我切换了5.6的版本试试,结果是连基本语法都已经报错

"require": {
    "php": ">=5.6.0",
    "topthink/framework": "~5.0.24",
    "overtrue/wechat": "~4.2",
    "endroid/qr-code": "^1.9",
    "topthink/think-captcha": "^1.0",
    "mtdowling/cron-expression": "^1.2",
    "phpmailer/phpmailer": "~6.0.6",
    "karsonzhang/fastadmin-addons": "~1.1.9",
    "overtrue/pinyin": "~3.0",
    "phpoffice/phpspreadsheet": "^1.2"
},      

4.接着,切回PHP7.0,继续猜问题

5.决定从报错位置开始找。分别找到

Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch      
Psr\EventDispatcher\EventDispatcherInterface::dispatch      
interface EventDispatcherInterface extends PsrEventDispatcherInterface{}      

接口这样继承应该没有问题才对

6.最后,查看Symfony和Psr的composer.json文件,终于发现了问题所在

"require": {
    "php": ">=7.2.5",
    "psr/event-dispatcher": "^1"
},      
"require": {
    "php": ">=7.2.0"
},      

7.解决问题后的感想:thinkphp5.0.24要求PHP5.6,EasyChat要求PHP7.0,其他的却要求更高的。。。这是万万没想到的