skip to Main Content

We are starting to use PHP 8 on new projects. But we are also migrating old projects to the new PHP 8. Problems occur when installing dependencies.

Because PHP 8 is relatively new, there are still many third-party packages that depend on older versions of PHP (mostly only due to outdated configuration).

My PHP version:

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

Example of composer install on Symfony project:

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.
...

Example composer update on Laravel 8 project:

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].

What is the best way to deal with this issue and solve this dependency problem?

2

Answers


  1. Chosen as BEST ANSWER

    Update:

    Definitive solution

    Use newer packages that are PHP 8 ready. Most packages are up to date.

    If some explicitly require lower versions of PHP, find a replacement. Or fork them and update.

    You can use the following as a temporary solution:

    Temporary quick solution

    Composer has the following possibilities:

    --ignore-platform-req=IGNORE-PLATFORM-REQ        Ignore a specific platform requirement (php & ext- packages). (multiple values allowed)
    --ignore-platform-reqs                           Ignore all platform requirements (php & ext- packages).
    

    Usage:

    # for composer install
    composer --ignore-platform-req=php install
    
    # for composer update
    composer --ignore-platform-req=php update
    
    # also works for require etc.
    

    Most packages use PHP version 7.x.x or lower, which is backward compatible with version 8. So no issue should arise.

    Update: There is also the possibility of forcing the version directly in the composer.json. However, this option was not usable for us, because we have already used a special syntax and features of php version 8 in the code. Even so, we already had version conflicts, whether we forced version 7 or 8 of PHP to the project.

    Example of forcing version in composer.json:

    {
        "config": {
           "platform": {
               "php": "7.0.0"
           }
        }
    }
    

    Use it only when you are sure that it does not cause any problems.


  2. downgrade your php version until packages that depend on it make an update ,
    or you must replace it with another,
    I have the same problem and I used the first solution.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search