简体   繁体   English

ArrayAccess 的 inheritance:未捕获的错误异常:Collection::offsetExists($key)

[英]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 ] 属性应该用来暂时抑制通知

error displaying below like this:错误显示如下:

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):

  1. brew unlink php@8.1 brew 取消链接 php@8.1
  2. brew link php@8.0 or lower brew 链接 php@8.0 或更低版本

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.

相关问题 (2/2)ErrorException属性[CampaignID]在此集合实例上不存在 - (2/2) ErrorException Property [CampaignID] does not exist on this collection instance Collection.php 第 1477 行中的 ErrorException:未定义偏移量:0 - ErrorException in Collection.php line 1477: Undefined offset: 0 Collection.php行1043中的ErrorException:未定义的偏移量:在laravel中为0 - ErrorException in Collection.php line 1043: Undefined offset: 0 in laravel Laravel 5.3分页-Collection.php第432行中的ErrorException - Laravel 5.3 Pagination - ErrorException in Collection.php line 432 Laravel 将 Excel 导入 DB:ErrorException 未定义数组键“名称” - Laravel Import Excel into DB: ErrorException Undefined array key "name" Laravel 9 在部署后出现“PHP 致命错误:未捕获的 ErrorException:方法 ReflectionParameter::getClass() 已弃用” - Laravel 9 is getting "PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in" after deployment 将集合转换为键值集合 - Convert collection to key value collection Laravel 5错误500服务器错误。 未捕获的ErrorException:file_put_contents(/ var / www / laravel / storage / framework / views / - Laravel 5 error 500 server error. Uncaught ErrorException: file_put_contents(/var/www/laravel/storage/framework/views/ ErrorException 未定义数组键 0(查看:C:\Users\Teacher\CNHSSystem\resources\views\section\index.blade.php) - ErrorException Undefined array key 0 (View: C:\Users\Teacher\CNHSSystem\resources\views\section\index.blade.php) Laravel Group 2按键收集 - Laravel group 2 Collection by key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM