HEROKU error: During inheritance of ArrayAccess

HEROKU error: During inheritance of ArrayAccess

这是 heroku 的日志,我之前版本的代码是 运行 完美的,但我更改了一些代码并出现了这个错误。 回滚现在无法解决同样的错误...

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/php
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
       - php (8.1.0)
       - ext-mbstring (bundled with php)
       - composer (2.1.14)
       - apache (2.4.51)
       - nginx (1.20.2)
-----> Installing dependencies...

 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 in /tmp/build_3007ab05/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1349

我最近遇到了完全相同的错误。我本地的 php 版本是 8.0.13 并且运行正常,但是当我将它上传到 heroku 时(这里使用的 php 版本是 8.1)我得到了错误。

为了解决这个问题,我将 composer.json 中的 php 版本指定为与我正在使用的完全相同的本地 php 版本,如下所示:

{
  "require": {
    "php": "8.0.13"
  }
}

不要忘记更新 composer.lock,然后将其上传到 heroku。 Heroku 将使用该版本。

我知道不建议根据 https://devcenter.heroku.com/articles/php-support 指定确切的版本,但它作为一种解决方法工作正常。