From 031e30b9f08bd68bc041581b8a3c19691c250ebc Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Fri, 17 Apr 2026 09:59:16 +0200 Subject: [PATCH] [BUGFIX] Make InstalledVersions work again When including multiple autoload.php files during the same runtime, Composer InstalledVersions relies on the registered autoloaders to be able to resolve all available packages. If class alias loader is now calling ->unregister API, the static registry of available classes is removed, which does not reflect the state when class alias loader is registered. Therefore, we now call spl_autoload_unregister ourselves instead of using the API, because the classes will be loadable, just not directly but proxied through class alias loader --- src/ClassAliasLoader.php | 2 +- tests/Unit/ClassAliasLoaderTest.php | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ClassAliasLoader.php b/src/ClassAliasLoader.php index 24be55c..95077e9 100644 --- a/src/ClassAliasLoader.php +++ b/src/ClassAliasLoader.php @@ -98,7 +98,7 @@ public function getClassNameForAlias($aliasOrClassName) */ public function register($prepend = false) { - $this->composerClassLoader->unregister(); + spl_autoload_unregister(array($this->composerClassLoader, 'loadClass')); spl_autoload_register(array($this, 'loadClassWithAlias'), true, $prepend); } diff --git a/tests/Unit/ClassAliasLoaderTest.php b/tests/Unit/ClassAliasLoaderTest.php index e27ba9c..bc8d5c6 100644 --- a/tests/Unit/ClassAliasLoaderTest.php +++ b/tests/Unit/ClassAliasLoaderTest.php @@ -46,15 +46,6 @@ public function tearMeDown() $this->subject->unregister(); } - /** - * @test - */ - public function registeringTheAliasLoaderUnregistersComposerClassLoader() - { - $this->composerClassLoaderMock->expects($this->once())->method('unregister'); - $this->subject->register(); - } - /** * @test */