【发布时间】:2021-06-18 10:17:39
【问题描述】:
我们开始在新项目中使用 PHP 8。但是我们也在将旧项目迁移到新的 PHP 8。安装依赖项时会出现问题。
由于 PHP 8 相对较新,仍然有很多第三方包依赖于旧版本的 PHP(大多只是因为配置过时)。
我的 PHP 版本:
martin@empire:~$ php -v
PHP 8.0.3 (cli) (built: Mar 5 2021 07:54:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies
composer install 在 Symfony 项目中的示例:
martin@empire:~/projects/twig-example$ composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- twig/twig is locked to version v2.3.0 and an update of this package was not requested.
- twig/twig v2.3.0 requires php ^7.0 -> your php version (8.0.3) does not satisfy that requirement.
Problem 2
- twig/twig v2.3.0 requires php ^7.0 -> your php version (8.0.3) does not satisfy that requirement.
...
在 Laravel 8 项目上的示例 composer update:
martin@empire:~/projects/collabquest-api$ composer update
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- jwilsson/spotify-web-api-php[3.6.0, ..., 3.6.2] require php ^7.0 -> your php version (8.0.3) does not satisfy that requirement.
- Root composer.json requires jwilsson/spotify-web-api-php ^3.6 -> satisfiable by jwilsson/spotify-web-api-php[3.6.0, 3.6.1, 3.6.2].
处理这个问题和解决这个依赖问题的最佳方法是什么?
【问题讨论】:
-
...错误信息有什么不清楚的地方吗?如果要使用 PHP 8,为什么不将包更新到与 PHP 8 兼容的版本?
-
问题是我们还使用了还没有 PHP 8 更新的包。因此这个问题与依赖项有关。降级整个项目的 PHP 版本也是不可能的,因为我们已经在代码中使用了 PHP 8 的特性。我们使用开关“--ignore-platform-req=php”临时解决了这个问题
-
是否有任何理由,例如:any,使用这种旧版本的 Twig?为什么不更新呢?
-
@MartinOsusky,如果您有解决方案,请将其添加到答案部分而不是您的问题中(特别是当解决方案绝对是错误提示时;))。
-
@gp_sflover 一天前加的,现在只回复cmets :)
标签: php laravel symfony composer-php php-8