composer: Composer 2.2, running composer update uses incorrect composer source file somehow

Hi

This is something weird that I encountered after upgrading to composer 2.2.1 I have 2 different Magento2 projects, they both run the same version of Magento (2.3.7-p2) but have different custom dependencies. In one project I have no problem using composer 2.2.1, but in the other project, I get this error when I try to run composer update:

PHP Fatal error:  Uncaught Error: Call to undefined method Composer\Installer::setPlatformRequirementFilter() in phar://composer.phar/src/Composer/Command/UpdateCommand.php:239
Stack trace:
#0 phar://composer.phar/vendor/symfony/console/Command/Command.php(245): Composer\Command\UpdateCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 phar://composer.phar/vendor/symfony/console/Application.php(835): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 phar://composer.phar/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Composer\Command\UpdateCommand), Object(Symfony\Component\Console\Input\A in phar://composer.phar/src/Composer/Command/UpdateCommand.php on line 239

So it can’t find that setPlatformRequirementFilter method in Composer\Installer. Which is strange because it exists in the phar file. Magento2 does come with composer/composer as dependency as well, which is currently at version 2.0.13 and can’t be updated further for some reason I haven’t looked into yet (in both projects). That version of composer does not have that setPlatformRequirementFilter method yet. So my guess is that while executing composer update, somehow composer tries to load Composer\Installer from vendor/composer/composer instead of from the composer.phar file. But only on one project and not in the other, which is very strange …

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 25 (14 by maintainers)

Most upvoted comments

@hostep no worries. you threw me off with the composer/composer require because it was in fact not the root cause of the problem, which is why I thought this was a somewhat bogus issue for so long, but glad we figured it out eventually.

Hi, just for information, I was facing the same kind of issue with Magento 2.4.3 and composer 2.2.2 :

  • No issue to run composer create --repository=https://repo.magento.com/ magento/project-community-edition m243 2.4.3
  • But then, as I was trying to add a composer repository with composer config repositories.my-repo path my-own-modules/something/, an error was thrown :
PHP Fatal error:  Uncaught TypeError: Argument 3 passed to Composer\Package\Locker::__construct() must be an instance of Composer\Repository\RepositoryManager, instance of Composer\Installer\InstallationManager given, called in phar:///usr/local/bin/composer/src/Composer/Factory.php on line 446 and defined in /var/www/html/vendor/composer/composer/src/Composer/Package/Locker.php:54
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/Factory.php(446): Composer\Package\Locker->__construct(Object(Composer\IO\ConsoleIO), Object(Composer\Json\JsonFile), Object(Composer\Installer\InstallationManager), '{\n    "name": "...', Object(Composer\Util\ProcessExecutor))
#1 phar:///usr/local/bin/composer/src/Composer/Factory.php(643): Composer\Factory->createComposer(Object(Composer\IO\ConsoleIO), Array, false, '/var/www/html', true, false)
#2 phar:///usr/local/bin/composer/src/Composer/Console/Application.php(445): Composer\Factory::create(Object(Composer\IO\ConsoleIO), NULL, false, false)
#3 phar:///usr/local/bin/composer/src/Compo in /var/www/html/vendor/composer/composer/src/Composer/Package/Locker.php on line 54

Fatal error: Uncaught TypeError: Argument 3 passed to Composer\Package\Locker::__construct() must be an instance of Composer\Repository\RepositoryManager, instance of Composer\Installer\InstallationManager given, called in phar:///usr/local/bin/composer/src/Composer/Factory.php on line 446 and defined in /var/www/html/vendor/composer/composer/src/Composer/Package/Locker.php:54
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/Factory.php(446): Composer\Package\Locker->__construct(Object(Composer\IO\ConsoleIO), Object(Composer\Json\JsonFile), Object(Composer\Installer\InstallationManager), '{\n    "name": "...', Object(Composer\Util\ProcessExecutor))
#1 phar:///usr/local/bin/composer/src/Composer/Factory.php(643): Composer\Factory->createComposer(Object(Composer\IO\ConsoleIO), Array, false, '/var/www/html', true, false)
#2 phar:///usr/local/bin/composer/src/Composer/Console/Application.php(445): Composer\Factory::create(Object(Composer\IO\ConsoleIO), NULL, false, false)
#3 phar:///usr/local/bin/composer/src/Compo in /var/www/html/vendor/composer/composer/src/Composer/Package/Locker.php on line 54

After doing composer self-update --snapshot, the error disappears.

Sorry, I understand the issue has become quite a mess. The steps to reproduce are in: https://github.com/composer/composer/issues/10401#issuecomment-1002136725 Magento comes with a requirement on both composer/composer and laminas/laminas-zendframework-bridge.

The issue is: When I execute a globally installed composer.phar file (version 2.2.2), it starts executing code inside the phar, but the moment it loads laminas/laminas-zendframework-bridge it starts switching to the source code of composer/composer which is installed in vendor. Probably due to you guys loading in another autoload file in laminas/laminas-zendframework-bridge.

What I expect to happen, is when I run a globally installed composer.phar file, it executes all the code from that file, and doesn’t suddenly switch to running source code from an installed composer/composer repository that got installed via composer. Which could potentially have a completely different version than the globally installed composer.phar file.

Hope this makes it a bit more clear?

Hmm, this might be a bug introduced in https://github.com/laminas/laminas-zendframework-bridge/pull/90 If I return null; in that getClassLoaderFromVendorDirectory method that got introduced there, I get rid of this bug here.

@boesing, @Ocramius: any ideas? Do you agree this might be a bug in laminas/laminas-zendframework-bridge (I’m using version 1.4.1)? Should I open a new issue over there?

Update: downgrading laminas/laminas-zendframework-bridge to version 1.4.0 solves my issue. So this is either a bug in laminas/laminas-zendframework-bridge version 1.4.1 or a bug in composer/composer 2.2.0+ or a combination of both I think …