参考-Composer错误“您的PHP版本不满足要求"升级PHP之后 [英] Reference - Composer error "Your PHP version does not satisfy requirements" after upgrading PHP

查看:124
本文介绍了参考-Composer错误“您的PHP版本不满足要求"升级PHP之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将PHP从7.4更新到8.0之后,我在现有项目上运行了 composer update ,并得到了如下错误:

After updating PHP from 7.4 to 8.0, I ran composer update on my existing project, and got an error like this:

  • acme/some-package [1.0.0,...,1.4.0]需要php ^ 5.6.4 ||^ 7.0->您的php版本(8.0.3)不满足该要求.

这是什么意思,我该如何解决?

What does this mean, and how do I fix it?

(这是一个参考答案,旨在涵盖一个经常遇到的问题.该场景只是一个示例.另请参见:"

推荐答案

问题

以及所需的其他软件包的版本,Composer软件包可以指定它们支持的PHP版本.

The Problem

As well as the versions of other packages they require, Composer packages can specify the versions of PHP which they support.

在解析要安装的软件包的版本时,Composer必须找到与 all 约束相匹配的版本:

While resolving the versions of packages to install, Composer has to find versions which match all the constraints in place:

  • 您在 composer.json
  • 中为依赖项指定的版本约束
  • 每个软件包为其 依赖项指定的版本约束
  • 每个软件包支持的PHP版本
  • The version constraints you've specified for dependencies in your composer.json
  • The version constraints each package has specified for its dependencies
  • The PHP versions each package supports

如果没有满足所有这些约束的软件包,您将得到一个错误.

If there is no package that satisfies all of those constraints, you will get an error.

请注意,PHP版本的版本限制遵循与其他撰写者约束相同的规则.因此, ^ 7.0 的约束表示"7.0.0以上的7.x的任何版本",并且 not 包括8.0.

Note that the version constraint for PHP version follows the same rules as other composer constraints. So a constraint of ^7.0 means "any version of 7.x above 7.0", and does not include 8.0.

要解决此问题,您需要放松以下约束之一:

To solve the problem, you need to relax one of those constraints:

  1. 查看错误消息中提到的软件包(示例中为 acme/some-package ),然后在
  1. Look at the package mentioned in the error message (acme/some-package in the example) and find it on Packagist (or whatever custom package source you have configured).
  2. See if a newer version exists that supports your PHP version.
  3. If it doesn't, you'll need to find out what's needed to add that support. This might mean checking out the project directly, running its tests, and submitting a patch to mark it as compatible with the new version.
  4. If (when) support has been added, you'll need to make sure your composer.json, and other packages you depend on, don't exclude that new version. For instance, if you currently depend on acme/some-package version ^1.0, but PHP 8.0 is only supported from version 2.2.0 onwards, you'll need to change your constraint to ^2.2, and make sure your application is still compatible.

临时解决方法

有时候,您可以肯定您的应用程序可以与以前使用的相同版本的软件包一起正常运行.在这种情况下,您可以使用 platform 配置变量 composer.json 中,假装您仍在使用旧版本.这仅应作为临时解决方法或用于测试,因为这意味着将安装软件包,这些软件包可能会在新的PHP版本上完全损坏.

Temporary Workaround

Sometimes, you're pretty sure your application will run fine with the same versions of packages as you were previously using. In that case, you can use the platform configuration variable in your composer.json to pretend you're still using the old version. This should only be done as a temporary workaround or for testing as it means packages will be installed which may be completely broken on your new PHP version.

例如:

{
    "config": {
        "platform": {
             "php": "7.4.999"
        }
    }
}

另请参见"在作曲家中覆盖PHP基本依赖项"

这篇关于参考-Composer错误“您的PHP版本不满足要求"升级PHP之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆