【问题标题】:Laravel app stopped working after upgrading to php 8Laravel 应用程序在升级到 php 8 后停止工作
【发布时间】:2021-03-20 22:30:26
【问题描述】:

将我的 mac 更新到 php 8 laravel 应用程序停止工作后,这是我得到的错误:

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945

我试图通过调查代码来解决这个问题,但没有成功

【问题讨论】:

    标签: php laravel php-8


    【解决方案1】:

    解决方案

    正如here 解释的那样,最新版本的 laravel 6、7 和 8 已对 php 8 进行了所需的更改。您所要做的就是:

    1- 将 php 8 添加到您的 composer.json(我保留了 v7.4,以防生产服务器尚不支持 php 8)

    "php": "^7.4|^8.0",
    

    2- 运行 composer update 将您的 laravel 更新到最新版本

    composer update
    

    3- 确保更新以下库,因为它们存在于所有 laravel 应用程序中

    PHP to php:^8.0
    Faker to fakerphp/faker:^1.9.1
    PHPUnit to phpunit/phpunit:^9.3
    

    4- 检查是否有任何其他需要更新的库,如果它们不支持 php 8,请贡献。但是您应该很好地使用大多数库,因为它们有活跃的贡献者。

    解释问题

    如上所述here

    PHP 8 在 PHP 类型系统中引入了多项改进,例如引入了联合类型、混合类型等等。

    随着这些变化,反射 API 中的某些方法 ReflectionParameter 产生不正确的结果。

    在 PHP 8 中,ReflectionParameter 类的以下方法是 已弃用:

    ReflectionParameter::getClass()
    ReflectionParameter::isArray()
    ReflectionParameter::isCallable()
    

    ReflectionParamter::getType() 是替换的推荐方法 不推荐使用的方法。此方法在 PHP 7.0 及更高版本中可用。

    【讨论】:

    • 我更新了我的 composer.json 文件,但是当我运行 composer update 命令时,我仍然收到“已弃用”错误,因此它看起来像是一个 catch-22,因为 composer 运行了“artisan clear-compiled " 命令在开始,这已经导致错误!有任何想法吗?我也不太确定您的第 3 步是什么意思,我是否必须进入库并检查他们的 composer.json 文件?
    • 我通过从 composer json 中临时删除“pre-update-cmd”来使其工作。我还必须将 laravel/socialite 升级到“^5.1”。无论如何,感谢您的帮助!
    • @matthiku 我不认为你做的事情很好(删除 pre-update-cmd)我的第 3 步是更新 composer.yml 文件中的那些依赖项
    • 运行composer update 后,我收到一条错误消息Killed。我必须将作曲家升级到版本 2 才能正常工作。
    • Faker 1.9.1 在我的情况下抛出一个错误。相反,我保留了"fzaninotto/faker": "~1.4",它工作正常。
    【解决方案2】:

    在你的虚拟机(xampp 或服务器)中检查你的 php 版本。

    php --version
    

    那个版本是 PHP 8 吗?我对吗?这就是问题的原因:

    PHP 8 在 PHP 类型系统中引入了多项改进,例如引入了联合类型、混合类型等等。

    通过这些更改,Reflection API 的 ReflectionParameter 中的某些方法会产生不正确的结果。

    在 PHP 8 中,不推荐使用 ReflectionParameter 类中的以下方法:

    • 反射参数::getClass()
    • 反射参数::isArray()
    • ReflectionParameter::isCallable()
    • 反射参数::getType()

    将你的 php 版本降级到 7.4,你的 Laravel 应用就会像魅力一样运行!

    【讨论】:

    • 这对医疗有效
    【解决方案3】:

    我有类似的问题。但是在我注意到这个问题之前,我已经运行了brew updatebrew cleanup。我做了什么:

    1. 我从brew cleanup 注意到了这个错误:
    Error: The `brew link` step did not complete successfully
    The formula built, but is not symlinked into /usr/local
    Could not symlink bin/node
    Target /usr/local/bin/node
    already exists. You may want to remove it:
      rm '/usr/local/bin/node'
    
    To force the link and overwrite all conflicting files:
      brew link --overwrite heroku-node
    
    1. 我运行了命令:
    brew link --overwrite composer
    composer upgrade
    composer update
    

    这对我有用

    【讨论】:

      猜你喜欢
      • 2017-02-12
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多