Laravelでサーバーを起動した時にDuring inheritance of ArrayAccess: が出た時の対処法 - Hashimoto-Noriaki/laravel-php-memo GitHub Wiki
エラーが起きた背景
Laravelをインストールし、php artisan serveでサーバーを起動した時に 下のようなエラーが出ました。
拡大するとこんな感じです。
During inheritance of ArrayAccess: Uncaught ErrorException: Return type of
Illuminate\Support\Collection::offsetExists($key) should either be compatib
le with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTyp
eWillChange] attribute should be used to temporarily suppress the notice in
/Users/hashimotonoriaki/Applications/MAMP/htdocs/task_test/vendor/laravel/
framework/src/Illuminate/Support/Collection.php:1277
調べてみたらバージョンがうまく対応できていないのが原因でした。
解決した方法
前提条件としてvimを導入していること前提で進めていきます。
まず最初に***.bash_profileを作成***します。
$ touch ~/.bash_profile
touchファイルで空のファイルを作成します。
$ ls -a
これで .bash_profile ができているか確認します。 できていたらvimで.bash_profileを編集します。
$ vi .bash_profile
そして
export PATH=/Applications/MAMP/bin/php/php*.*.*/bin:$PATH
を記載します。 ***の部分にhtdocsの中のphpの最新のバージョンを入れます。
この場合だと
8.0.8ですね。
vimで保存して
$ export PATH=/Applications/MAMP/bin/php/php8.0.8/bin:$PATH
を実行します。
その後に
$ source .bash_profile
を実行します。 これでLaravelが使えるようになりました。
バージョンもしっかり確認できました。
$ php artisan --version
//Laravel Framework 6.20.44
参考資料
https://qiita.com/flatwhite/items/76f349eb3746d636697d
https://qiita.com/takutoki/items/021b804b9957fe65e093
https://qiita.com/Hashimoto-Noriaki/items/3df578d53a103a0ca0a0