Composer 无法识别 PHP 7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34146214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:47:13  来源:igfitidea点击:

Composer is not recognizing PHP 7

phpcomposer-phptravis-ci

提问by azngunit81

I created a travis profile to test my project from PHP 5.6 to PHP 7.

我创建了一个 travis 配置文件来测试我的项目从 PHP 5.6 到 PHP 7。

I am getting the following error when composer is run:

运行 composer 时出现以下错误:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - This package requires php ~5.4 but your PHP version (7.0.1-dev) does not satisfy that requirement.

the command that I am running is:

我正在运行的命令是:

composer update -n

with travis set to environment PHP 5.6 I do not run into this issue

将 travis 设置为环境 PHP 5.6 我没有遇到这个问题

采纳答案by Sven

A package that you use, or your own software itself, explicitly requires a PHP 5.x version (~5.4), with x being at least 4, or higher (i.e. it would run with PHP 5.5, 5.6, or even 5.10 if it would exist).

您使用的软件包或您自己的软件本身明确需要 PHP 5.x 版本 ( ~5.4),x 至少为 4 或更高(即,如果存在,它将与 PHP 5.5、5.6 或什至 5.10 一起运行)。

This package does not allow PHP 7. That's why you cannot run composer updatesuccessfully.

此包不允许 PHP 7。这就是您无法composer update成功运行的原因。

回答by localheinz

If the platform requirement is in your root package, you can solve it by amending composer.jsonas such

如果平台要求在您的根包中,您可以通过composer.json这样修改来解决它

{
    "require": {
        "php": "~5.4 | ^7.0"
    } 
}

You could also try to ignore platform requirements, but depends on whether you actually want to see that happen:

您也可以尝试忽略平台要求,但这取决于您是否真的希望看到这种情况发生:

$ composer install --ignore-platform-reqs

For reference, see https://getcomposer.org/doc/03-cli.md#install.

如需参考,请参阅https://getcomposer.org/doc/03-cli.md#install

回答by baoniu

check your composer.json file, delete this code:

检查您的 composer.json 文件,删除此代码:

 "config": {
    "bin-dir": "bin",
    "platform": {
        "php": "5.x.1"  // Or change 5.x.1 to your php version
    }
},

回答by D.Y.F

change phpdefault V

更改php默认 V

sudo update-alternatives --config php