From e0cce2bfb00c8c828f2a70a8beb4db4fc7f60888 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 6 Apr 2022 22:07:16 +0200 Subject: [PATCH] Allow autoload to run on 5.6 still, add early exits when running composer or autoload.php with outdated PHP versions, fixes #10714, refs #10709 --- bin/composer | 5 +++++ src/Composer/Autoload/AutoloadGenerator.php | 8 +++++++- .../Test/Autoload/Fixtures/autoload_functions.php | 5 +++++ .../Fixtures/autoload_functions_by_dependency.php | 5 +++++ .../Fixtures/autoload_real_files_by_dependency.php | 2 +- .../Test/Autoload/Fixtures/autoload_real_functions.php | 2 +- .../autoload_real_functions_with_include_paths.php | 2 +- ...tions_with_removed_include_paths_and_autolad_files.php | 2 +- .../Test/Autoload/Fixtures/autoload_real_include_path.php | 2 +- .../Test/Autoload/Fixtures/autoload_real_target_dir.php | 2 +- .../Test/Autoload/Fixtures/autoload_target_dir.php | 5 +++++ 11 files changed, 33 insertions(+), 7 deletions(-) diff --git a/bin/composer b/bin/composer index 55391b9b6..642714f56 100755 --- a/bin/composer +++ b/bin/composer @@ -5,6 +5,11 @@ if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') { echo 'Warning: Composer should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; } +if (PHP_VERSION_ID < 70205) { + echo 'Composer 2.3.0 dropped support for PHP <7.2.5 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; + exit(1); +} + setlocale(LC_ALL, 'C'); require __DIR__.'/../src/bootstrap.php'; diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 68f540bcf..4ed43d3ec 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -917,6 +917,11 @@ PLATFORM_CHECK; // autoload.php @generated by Composer +if (PHP_VERSION_ID < 50600) { + echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; + exit(1); +} + require_once $vendorPathToTargetDirCode; return ComposerAutoloaderInit$suffix::getLoader(); @@ -993,9 +998,10 @@ CLASSLOADER_INIT; INCLUDE_PATH; } + // keeping PHP 5.6+ compatibility for the autoloader here by using call_user_func vs getInitializer()() $file .= <<register(true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index 6b60558ae..e48c62574 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -27,7 +27,7 @@ class ComposerAutoloaderInitFilesAutoload spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - \Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)(); + call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); $loader->register(true); 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 12684a3ba..c91aac9ce 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 @@ -31,7 +31,7 @@ class ComposerAutoloaderInitFilesAutoload set_include_path(implode(PATH_SEPARATOR, $includePaths)); require __DIR__ . '/autoload_static.php'; - \Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)(); + call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); $loader->register(true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php index b512f21d1..941c2e0d2 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php @@ -27,7 +27,7 @@ class ComposerAutoloaderInitFilesAutoload spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - \Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)(); + call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); $loader->register(true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php index 1412c4fba..1c7d38f4c 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php @@ -27,7 +27,7 @@ class ComposerAutoloaderInitIncludePath spl_autoload_unregister(array('ComposerAutoloaderInitIncludePath', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - \Composer\Autoload\ComposerStaticInitIncludePath::getInitializer($loader)(); + call_user_func(\Composer\Autoload\ComposerStaticInitIncludePath::getInitializer($loader)); $loader->setUseIncludePath(true); spl_autoload_register(array('ComposerAutoloaderInitIncludePath', 'autoload'), true, true); 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 732175b2a..77dd94c19 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -27,7 +27,7 @@ class ComposerAutoloaderInitTargetDir spl_autoload_unregister(array('ComposerAutoloaderInitTargetDir', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - \Composer\Autoload\ComposerStaticInitTargetDir::getInitializer($loader)(); + call_user_func(\Composer\Autoload\ComposerStaticInitTargetDir::getInitializer($loader)); spl_autoload_register(array('ComposerAutoloaderInitTargetDir', 'autoload'), true, true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_target_dir.php index d117d6d48..52c462cd6 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_target_dir.php @@ -2,6 +2,11 @@ // autoload.php @generated by Composer +if (PHP_VERSION_ID < 50600) { + echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; + exit(1); +} + require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInitTargetDir::getLoader();