[英]inheritance of ArrayAccess: Uncaught ErrorException: Collection::offsetExists($key)
NB: Local server PHP Version 8.1.4, laravel project inside composer.json file have "php": "^7.2.5", version & "laravel/framework": "^7.0"注意:本地服务器 PHP 版本 8.1.4,composer.json 文件中的 laravel 项目有“php”:“^7.2.5”,版本和“laravel/framework”:“^7.0”
PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice PHP 致命错误:在 ArrayAccess 的 inheritance 期间:未捕获的错误异常:Illuminate\Support\Collection::offsetExists($key) 的返回类型应该与 ArrayAccess::offsetExists(mixed $offset): bool 兼容,或者#[\ReturnTypeWillChange ] 属性应该用来暂时抑制通知
in your composer.json update line在你的 composer.json 更新行
"php": "^7.3",
to到
"php": "^7.3|^8.1",
and run composer update并运行作曲家更新
You would need to upgrade your Laravel Framework version to at least version 8 and it's dependencies using composer.你需要将你的 Laravel 框架版本至少升级到版本 8,并且它是使用 composer 的依赖项。
Reference: https://laravel.com/docs/8.x/releases参考: https ://laravel.com/docs/8.x/releases
Or if you want to postpone it, you would need to add #[\ReturnTypeWillChange]
before declaring every function that throws the error.或者如果你想推迟它,你需要在声明每个抛出错误的函数之前添加#[\ReturnTypeWillChange]
。 This is highly not advisable.这是非常不可取的。
PS If you updated your PHP version you would have to change the PHP version in composer to the one used, in your case it should be "php": "^8.1.4"
PS 如果您更新了 PHP 版本,则必须将 composer 中的 PHP 版本更改为使用的版本,在您的情况下,它应该是"php": "^8.1.4"
That's a php version issue.这是 php 版本问题。 Upgrade laravel or downgrade PHP.升级 laravel 或降级 PHP。 This article covers how to downgrade the PHP version so it matches the Laravel Version.本文介绍如何降级 PHP 版本,使其与 Laravel 版本匹配。
https://bytexd.com/fix-laravel-return-type-of-illuminatesupportcollectionoffsetexistskey/ https://bytexd.com/fix-laravel-return-type-of-illuminatesupportcollectionoffsetexistskey/
In my case, using a mac, turns out my php version was 8.1 which somehow is not compatible with laravel version 7. Tho most of these answers are correct, but they did not fix my issues.在我的例子中,使用 mac,结果我的 php 版本是 8.1,不知何故与 laravel 版本 7 不兼容。虽然这些答案大部分都是正确的,但它们没有解决我的问题。 I followed these steps (if brew is installed):我遵循了这些步骤(如果安装了 brew):
Reference How can I easily switch between PHP versions on Mac OSX?参考如何在 Mac OSX 上轻松切换 PHP 版本?
run "composer update" on your project directory and it will work.在您的项目目录上运行“作曲家更新”,它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.