PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 20, 2022

[FIXED] How to limit a package's dependency to a certain PHP version in Composer?

 May 20, 2022     composer-php, package-managers, php, phpdotenv     No comments   

Issue

Our production server is PHP 5.5.24. A package I need (vlucas/dotenv) requires in its composer.json:

"symfony/polyfill-ctype": "^1.17"

Unfortunately version 1.20 of that symfony package requires 7.1, which causes Composer's platform check to fail. I cannot ignore the error/platform check because it results in a syntax error on PHP 5.5.

It seems that this does not work for sub-dependencies, just the package itself:

"config": {
    "platform": {
        "php": "5.5.24"
    }
}

I've completely deleted the vendor folder and done a fresh install. Upgrading the server is not an option.


Solution

You can just require an explicit version of a package without any additional constraints, and that will version-lock other dependencies.

Either manually add "symfony/polyfill-ctype": "1.17" to your composer.json file, or use composer require symfony/polyfill-ctype:1.17 from the command line.

I will warn you that this might cause you headaches in the future when you upgrade, so make sure that you document it somewhere. Specifically, you or someone else in the future will look at the code and say "we aren't even using that", and then remove it.



Answered By - Chris Haas
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing