diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index f03f85293..e46ba1463 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -372,9 +372,15 @@ require __DIR__ . '/ClassLoader.php'; class ComposerAutoloaderInit$suffix { + private static \$loader; + public static function getLoader() { - \$loader = new \\Composer\\Autoload\\ClassLoader(); + if (null !== static::\$loader) { + return static::\$loader; + } + + static::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader(); \$vendorDir = $vendorPathCode; \$baseDir = $appBaseDirCode; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index 6837914e3..07c8db3b4 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -6,9 +6,15 @@ require __DIR__ . '/ClassLoader.php'; class ComposerAutoloaderInitFilesAutoloadOrder { + private static $loader; + public static function getLoader() { - $loader = new \Composer\Autoload\ClassLoader(); + if (null !== static::$loader) { + return static::$loader; + } + + static::$loader = $loader = new \Composer\Autoload\ClassLoader(); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index bfeb45024..6cb37bb0b 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -6,9 +6,15 @@ require __DIR__ . '/ClassLoader.php'; class ComposerAutoloaderInitFilesAutoload { + private static $loader; + public static function getLoader() { - $loader = new \Composer\Autoload\ClassLoader(); + if (null !== static::$loader) { + return static::$loader; + } + + static::$loader = $loader = new \Composer\Autoload\ClassLoader(); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index ed8c68011..960df2e2a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -6,9 +6,15 @@ require __DIR__ . '/ClassLoader.php'; class ComposerAutoloaderInitTargetDir { + private static $loader; + public static function getLoader() { - $loader = new \Composer\Autoload\ClassLoader(); + if (null !== static::$loader) { + return static::$loader; + } + + static::$loader = $loader = new \Composer\Autoload\ClassLoader(); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir);