Safely Ignore Platform Requirements using Composer v2
Leonel Elimpe
by Leonel Elimpe
~1 min read

Tags

  • Composer
  • PHP

I’ve learned the hard way that blindly using Composer’s --ignore-platform-reqs can lead to issues like the downloading of package versions that are not compatible with your PHP version. I am on PHP 7.4 but packages using PHP 8 features were being downloaded, leading to this error:

syntax error, unexpected '|', expecting variable (T_VARIABLE)

It is safer to specify the platform requirement you would like to ignore using the --ignore-platform-req option of Composer v2:

composer install --ignore-platform-req=ext-pcntl

I added a script to composer.json to ease this:

Safely ignoring platform requirements using Composer v2

As seen above, to ignore multiple platform requirements you use the `–ignore-platform-req` multiple times.

Further reading