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

Monday, February 14, 2022

[FIXED] Composer installing incompatible package

 February 14, 2022     composer-php, package, php, php-7.3     No comments   

Issue

I have a composer.json file that includes the following:

"require": {
    "php": "~7.3.0",
    "ext-imagick": "*",
    "ext-apcu": "*",
    "ext-json": "*",
    "ext-blackfire": "*",
    "doctrine/doctrine-migrations-bundle": "^1.3",

The later use of --ignore-platform-reqs relates to the docker image not having those extensions, but the Heroku environment does.

The latter is requiring a package, which requires another package.

$ composer why ocramius/package-versions
doctrine/orm            v2.7.2  requires  ocramius/package-versions (^1.2)
ocramius/proxy-manager  2.8.0   requires  ocramius/package-versions (^1.8.0)

$ composer why ocramius/proxy-manager
doctrine/migrations  v1.8.1  requires  ocramius/proxy-manager (^1.0|^2.0)

This is installing code that uses PHP 7.4's property type declarations. This throws a big ugly error in PHP 7.3.

$ php -d memory_limit=-1 composer.phar update --ignore-platform-reqs
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 195 installs, 0 updates, 0 removals
  - Installing ocramius/package-versions (1.8.0): Loading from cache

Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in 
             /var/www/project/vendor/ocramius/package-versions/src/PackageVersions/Installer.php
             on line 33

Why am I always getting this version of ocramius/package-versions and how to do I prevent this error (and that package version) from happening?


Solution

The solution for me was to remove --ignore-platform-reqs. For any forward-leaning packages (any Ocramius package, for instance), this will either fail hard like this did, or you'll have several strange bugs you can't seem to track down the cause of.

What --ignore-platform-reqs does is it switches off the checks Composer makes to ensure that only packages compatible with the environment works. In this case, the offending package had a recent update to use PHP 7.4, and happened to use the new property type declarations in the Composer installer.

I had been battling several other weirdnesses (like the Doctrine's Entity Manager failing randomly, another Ocramius-related package), which all went away by removing the flag when I ran Composer. Whatever the reason I needed it years ago, I no longer do.

If you feel you need it, check out config.platform which seems to allow you to lie to Composer, or work to remove needing that flag altogether (why-ever you think you need it, get over it if possible).

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "7.0.3", "ext-something": "4.0.3"}.

https://getcomposer.org/doc/06-config.md#platform



Answered By - Jared Farrish
  • 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