IlluminateContainerContainer::get($id)的声明必须兼容PsrContainerContainerInterface::get(string$id)

安装了新的 Laravel 8 项目并在加载第一个实例时出现以下错误。这很奇怪,因为我把它放在一边,后来从 Laravel 5.8 -> 6 升级了另一个项目(工作正常),并在我去检查站点时遇到了类似的错误。

我已经清除了作曲家缓存,删除了供应商文件夹并重新安装,但似乎无法弄清楚。过去一天我一直在绞尽脑汁,似乎某些软件包版本不正确,但我不确定从哪里开始进行故障排除。

( ! ) 致命错误:IlluminateContainerContainer::get($id) 的声明必须与 /home/vagrant/ps/vendor/laravel/framework 中的 PsrContainerContainerInterface::get(string $id) 兼容/src/Illuminate/Container/Container.php 第 15 行

Call Stack
#   Time    Memory  Function    Location
1   0.0001  357784  {main}( )   .../index.php:0
2   0.0133  502360  require_once( '/home/vagrant/ps/bootstrap/app.php' )    .../index.php:47
3   0.0133  502360  spl_autoload_call ( )   .../app.php:14
4   0.0133  502424  ComposerAutoloadClassLoader->loadClass( ) .../app.php:14
5   0.0133  502424  ComposerAutoloadincludeFile( )    .../ClassLoader.php:322
6   0.0135  578336  include( '/home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Foundation/Application.php' )    .../ClassLoader.php:444
7   0.0135  578336  spl_autoload_call ( )   .../Application.php:29
8   0.0135  578392  ComposerAutoloadClassLoader->loadClass( ) .../Application.php:29
9   0.0135  578392  ComposerAutoloadincludeFile( )    .../ClassLoader.php:322
10  0.0138  588440  include( '/home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Container/Container.php' )   .../ClassLoader.php:444

回答

您使用的是什么版本的 PHP?看起来这个问题的发生是因为在psr/container五天前发布的 v1.0.0 和 v.1.1.0 之间添加了静态类型以弃用 PHP < 7.2

https://github.com/php-fig/container/blob/1.0.0/src/ContainerInterface.php#L23

https://github.com/php-fig/container/blob/1.1.0/src/ContainerInterface.php#L22

固定psr/container到 v1.0.0 应该可以解决这个问题,直到 Illuminate 更新

  • I've been trying to figure this one out for almost a week. Thank you so much for your answer here. plugged in ```"psr/container": "1.0.0"``` at the bottom of my composer.json, ran update, and then deployed and it works great now. Thank you so much for this answer @cLin

以上是IlluminateContainerContainer::get($id)的声明必须兼容PsrContainerContainerInterface::get(string$id)的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>