From d047f38f73629f876226f61331db6b889f4dcafe Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 22 Dec 2022 21:01:38 +0100 Subject: [PATCH] Make sure autoloader closures do not have a scope class set --- src/Composer/Autoload/AutoloadGenerator.php | 4 ++-- src/Composer/Autoload/ClassLoader.php | 4 ++-- .../Autoload/Fixtures/autoload_real_files_by_dependency.php | 4 ++-- .../Test/Autoload/Fixtures/autoload_real_functions.php | 4 ++-- .../Fixtures/autoload_real_functions_with_include_paths.php | 4 ++-- .../Test/Autoload/Fixtures/autoload_real_target_dir.php | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 625aee806..fc097a683 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1021,13 +1021,13 @@ REGISTER_LOADER; if ($useIncludeFiles) { $file .= << \$file) { (\$requireFile)(\$fileIdentifier, \$file); } diff --git a/src/Composer/Autoload/ClassLoader.php b/src/Composer/Autoload/ClassLoader.php index fd56bd7d8..44ee4c819 100644 --- a/src/Composer/Autoload/ClassLoader.php +++ b/src/Composer/Autoload/ClassLoader.php @@ -574,8 +574,8 @@ class ClassLoader * @param string $file * @return void */ - self::$includeFile = static function($file) { + self::$includeFile = \Closure::bind(static function($file) { include $file; - }; + }, null, null); } } 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 de62445d5..e9344b8a8 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 @@ -32,13 +32,13 @@ class ComposerAutoloaderInitFilesAutoloadOrder $loader->register(true); $filesToLoad = \Composer\Autoload\ComposerStaticInitFilesAutoloadOrder::$files; - $requireFile = static function ($fileIdentifier, $file) { + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } - }; + }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { ($requireFile)($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index fd621ad7d..8c3403612 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -32,13 +32,13 @@ class ComposerAutoloaderInitFilesAutoload $loader->register(true); $filesToLoad = \Composer\Autoload\ComposerStaticInitFilesAutoload::$files; - $requireFile = static function ($fileIdentifier, $file) { + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } - }; + }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { ($requireFile)($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php index b7f7fb87f..164a26309 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php @@ -36,13 +36,13 @@ class ComposerAutoloaderInitFilesAutoload $loader->register(true); $filesToLoad = \Composer\Autoload\ComposerStaticInitFilesAutoload::$files; - $requireFile = static function ($fileIdentifier, $file) { + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } - }; + }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { ($requireFile)($fileIdentifier, $file); } 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 579054e9a..99d784bc3 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -34,13 +34,13 @@ class ComposerAutoloaderInitTargetDir $loader->register(true); $filesToLoad = \Composer\Autoload\ComposerStaticInitTargetDir::$files; - $requireFile = static function ($fileIdentifier, $file) { + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } - }; + }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { ($requireFile)($fileIdentifier, $file); }