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

Monday, March 7, 2022

[FIXED] Composer installs unexpected polyfills. How to avoid installing them if they are unnecessary?

 March 07, 2022     composer-php, php, polyfills, symfony     No comments   

Issue

I'm using composer, and I have just updated guzzlehttp/guzzle. I'm astonished for the packages that are installed:

>composer update  guzzlehttp/guzzle
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 1 update, 0 removals
  - Installing symfony/polyfill-php72 (v1.17.0): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.17.0): Downloading (100%)
  - Installing symfony/polyfill-intl-idn (v1.17.0): Downloading (100%)
  - Updating guzzlehttp/guzzle (6.5.2 => 6.5.4): Downloading (100%)

I'm using php 7.4 with mbstring installed, and there is no reason these polyfills are installed. Composer is aware of the PHP version I'm using:

>composer show --platform
(...)
ext-mbstring        7.4.2    The mbstring PHP extension
(...)
php                 7.4.3    The PHP interpreter

I suspec that I have some misconfiguration somewhere, it doesn't make sense to me that these polyfills are installed.


Solution

The polyfills are installed in case the package is installed in a server that does not match the requirements. This way maximum portability and compatibility is achieved.

The way to avoid these packages from being installed if you know your project already depends on a specific platform version and or extensions, and thus you can are certain they are always going to be available on every deployment is to declare them on the replace section:

"replace": {  
        "symfony/polyfill-php72": "*",  
        "symfony/polyfill-mbstring": "*",  
}

This will prevent these packages being installed at all. But this will not make sure these capabilities are present when installing the application. For completeness sake, you should add the corresponding entries in the require section:

"require": {  
   "php": "^7.2",  
   "ext-mbstring": "*"
}

This is glossed over in the symfony/polyfill readme, but it only mentions polyfills for PHP versions, although the same logic applies for any other polyfill your project is certain to have enough capabilities as to not require, and that you could avoid installing altogether.

Still, if you do not do this, the performance hit is minimal, and should not be a cause for concern.



Answered By - yivi
  • 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