diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1a009fa23246a257fc9c2a17e396868bfb0b13ae..819a4d9ae29c02d2a433f9a77e4b507881fc94ac 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** - * Minimum allowed version of PHP. + * Minimum allowed version of PHP for Drupal to be bootstrapped. * * Below this version: * - The installer cannot be run. @@ -22,12 +22,13 @@ * - If a site managed to bypass all of the above, then an error is shown in * the status report and various fatal errors occur on various pages. * - * @see install.php + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_PHP instead. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @see https://www.drupal.org/node/2909361 + * @see install.php */ -const DRUPAL_MINIMUM_PHP = '7.3.0'; +const DRUPAL_MINIMUM_PHP = \Drupal::MINIMUM_PHP; /** * Minimum supported version of PHP. @@ -38,10 +39,12 @@ * that Drupal no longer supports that PHP version. * - An error is shown in the status report that the PHP version is too old. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_SUPPORTED_PHP instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_MINIMUM_SUPPORTED_PHP = '7.3.0'; +const DRUPAL_MINIMUM_SUPPORTED_PHP = \Drupal::MINIMUM_SUPPORTED_PHP; /** * Minimum recommended version of PHP. @@ -50,10 +53,12 @@ * message, but Drupal can still be installed. Used for (e.g.) PHP versions * that have reached their EOL or will in the near future. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::RECOMMENDED_PHP instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_RECOMMENDED_PHP = '7.3'; +const DRUPAL_RECOMMENDED_PHP = \Drupal::RECOMMENDED_PHP; /** * Minimum recommended value of PHP memory_limit. @@ -62,10 +67,12 @@ * contributed modules to be installed prior to hitting the limit. However, * 40M is the target for the Standard installation profile. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M'; +const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = \Drupal::MINIMUM_PHP_MEMORY_LIMIT; /** * Error reporting level: display no errors. diff --git a/core/includes/install.inc b/core/includes/install.inc index ce7df4759e9500462f613110c4b72e55cbc3a044..95c9d2b83ab34c6412d7de50da5121dfff6f914c 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -1099,7 +1099,7 @@ function install_profile_info($profile, $langcode = 'en') { 'description' => '', 'version' => NULL, 'hidden' => FALSE, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, 'config_install_path' => NULL, ]; $profile_path = drupal_get_path('profile', $profile); diff --git a/core/install.php b/core/install.php index 8fae042ed9e5c145d0acec87349ece64a6022140..775ee745c15a380bd205ff379097b480f2b1715a 100644 --- a/core/install.php +++ b/core/install.php @@ -21,12 +21,16 @@ */ define('MAINTENANCE_MODE', 'install'); -// Exit early if running an incompatible PHP version to avoid fatal errors. -// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not -// yet available. It is defined in bootstrap.inc, but it is not possible to -// load that file yet as it would cause a fatal error on older versions of PHP. +// Exit early if an incompatible PHP version is in use, so that the user sees a +// helpful error message rather than a whitescreen from any fatal errors due to +// the incompatible version. The minimum version is also hardcoded (instead of +// \Drupal::MINIMUM_PHP), to avoid any fatal errors that might result from +// loading the autoloader or core/lib/Drupal.php. Note: Remember to update the +// hardcoded minimum PHP version below (both in the version_compare() call and +// in the printed message to the user) whenever \Drupal::MINIMUM_PHP is +// updated. if (version_compare(PHP_VERSION, '7.3.0') < 0) { - print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.'; + print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement">Environment requirements of Drupal 9</a> page for more information.'; exit; } diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 461fda85470692cbd5f6e90e686d20c9369a2033..c2fd03d1ee5bb0126ed6ebc4e1d69d2afaa4ed76 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -92,6 +92,53 @@ class Drupal { */ const CORE_MINIMUM_SCHEMA_VERSION = 8000; + /** + * Minimum supported version of PHP. + * + * Below this version: + * - New sites cannot be installed, except from within tests. + * - Updates from previous Drupal versions can be run, but users are warned + * that Drupal no longer supports that PHP version. + * - An error is shown in the status report that the PHP version is too old. + */ + const MINIMUM_SUPPORTED_PHP = '7.3.0'; + + /** + * Minimum allowed version of PHP for Drupal to be bootstrapped. + * + * Below this version: + * - The installer cannot be run. + * - Updates cannot be run. + * - Modules and themes cannot be enabled. + * - If a site managed to bypass all of the above, then an error is shown in + * the status report and various fatal errors occur on various pages. + * + * Note: To prevent the installer from having fatal errors on older versions + * of PHP, the value of this constant is hardcoded twice in core/install.php: + * - Once as a parameter of version_compare() + * - Once in the error message printed to the user immediately after. + * Remember to update both whenever this constant is updated. + */ + const MINIMUM_PHP = '7.3.0'; + + /** + * Minimum recommended value of PHP memory_limit. + * + * 64M was chosen as a minimum requirement in order to allow for additional + * contributed modules to be installed prior to hitting the limit. However, + * 40M is the target for the Standard installation profile. + */ + const MINIMUM_PHP_MEMORY_LIMIT = '64M'; + + /** + * Minimum recommended version of PHP. + * + * Sites installing Drupal on PHP versions lower than this will see a warning + * message, but Drupal can still be installed. Used for (e.g.) PHP versions + * that have reached their EOL or will in the near future. + */ + const RECOMMENDED_PHP = '7.3'; + /** * The currently active container object, or NULL if not initialized yet. * diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 60b08cc8b549dd78a879f217818f50104223ff54..c05d892b24bfd8a9d35669e25bd73c6cb9b3be9c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -28,7 +28,7 @@ class ModuleExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php index 7c415168d8adf5a37858ed3a1280128bd5958472..5ef9c451fdd5bd181f960a32777bd33979a63eda 100644 --- a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php @@ -22,7 +22,7 @@ class ProfileExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php index c4d39ef6008bf385a0de3e082dc01b1dff9df977..5b9bd692ef74b64d96fe7d3e0264373bf21454ad 100644 --- a/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php @@ -21,7 +21,7 @@ class ThemeEngineExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php index 41ae9310bf4e52aa827293dc84ddb1066fb65107..c84299abe355a9046f87b4b9d994ddea37c98485 100644 --- a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php @@ -48,7 +48,7 @@ class ThemeExtensionList extends ExtensionList { ], 'screenshot' => 'screenshot.png', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, 'libraries' => [], 'libraries_extend' => [], 'libraries_override' => [], diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index e2ffe1320bf3feee1fddb77276855fe11900acd2..1e4f4b12cdaa541f0b08c9b779290c4307a10506 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -987,8 +987,8 @@ function hook_requirements($phase) { 'title' => t('PHP'), 'value' => ($phase == 'runtime') ? Link::fromTextAndUrl(phpversion(), Url::fromRoute('system.php'))->toString() : phpversion(), ]; - if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { - $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]); + if (version_compare(phpversion(), \Drupal::MINIMUM_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => \Drupal::MINIMUM_PHP]); $requirements['php']['severity'] = REQUIREMENT_ERROR; } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index dc39b9a88cc5b1198bace12475f23bf0e5c65bb1..a981accf37a82ba196fbcbe948065d4a09c428d2 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -202,19 +202,19 @@ function system_requirements($phase) { } // Check if the PHP version is below what Drupal supports. - if (version_compare($phpversion, DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { - $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', + if (version_compare($phpversion, \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Environment requirements of Drupal 9</a> page for more information.', [ - '%version' => DRUPAL_MINIMUM_SUPPORTED_PHP, - '%recommended' => DRUPAL_RECOMMENDED_PHP, - ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php', + '%version' => \Drupal::MINIMUM_SUPPORTED_PHP, + '%recommended' => \Drupal::RECOMMENDED_PHP, + ':php_requirements' => 'https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement', ] ); $requirements['php']['severity'] = REQUIREMENT_ERROR; // If the PHP version is also below the absolute minimum allowed, it's not // safe to continue with the requirements check. - if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) { + if (version_compare($phpversion, \Drupal::MINIMUM_PHP) < 0) { return $requirements; } // Otherwise downgrade the error to a warning during updates. Even if there @@ -235,8 +235,8 @@ function system_requirements($phase) { // For PHP versions that are still supported but no longer recommended, // inform users of what's recommended, allowing them to take action before it // becomes urgent. - elseif ($phase === 'runtime' && version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) { - $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']); + elseif ($phase === 'runtime' && version_compare($phpversion, \Drupal::RECOMMENDED_PHP) < 0) { + $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => \Drupal::RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']); $requirements['php']['severity'] = REQUIREMENT_INFO; } @@ -463,16 +463,16 @@ function system_requirements($phase) { 'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit, ]; - if (!Environment::checkMemoryLimit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) { + if (!Environment::checkMemoryLimit(\Drupal::MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) { $description = []; if ($phase == 'install') { - $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } elseif ($phase == 'update') { - $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } elseif ($phase == 'runtime') { - $description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } if (!empty($description['phase'])) { diff --git a/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php b/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php index a347200ad814ad7becba42da050013deb9a62cc7..dab1ef3db07c30a44914ad3ad13a85b16f8c5283 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php @@ -82,7 +82,3 @@ public function testFind() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.0.8'); -} diff --git a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php index 12a0d88e1c763cc9d5dea590a1f775491bdfa6d9..594f29eabc06a8a3efe214ce599cd030caacb00b 100644 --- a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php @@ -86,7 +86,7 @@ public function tearDown(): void { * Tests the quick-start command. */ public function testQuickStartCommand() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->markTestSkipped(); } if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { @@ -144,7 +144,7 @@ public function testQuickStartCommand() { * Tests that the installer throws a requirement error on older PHP versions. */ public function testPhpRequirement() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) >= 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) >= 0) { $this->markTestSkipped(); } @@ -167,7 +167,7 @@ public function testPhpRequirement() { $error_output = $process->getErrorOutput(); $this->assertStringContainsString('Your PHP installation is too old.', $error_output); $this->assertStringContainsString('Drupal requires at least PHP', $error_output); - $this->assertStringContainsString(DRUPAL_MINIMUM_SUPPORTED_PHP, $error_output); + $this->assertStringContainsString(\Drupal::MINIMUM_SUPPORTED_PHP, $error_output); // Stop the web server. $process->stop(); @@ -177,7 +177,7 @@ public function testPhpRequirement() { * Tests the quick-start commands. */ public function testQuickStartInstallAndServerCommands() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->markTestSkipped(); } if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php index 254bde86d66c6eaf220dedd1530edef1db12a8bb..3c2eb03d528640dad39467d2cf395812d337eeb5 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php @@ -155,7 +155,3 @@ public function testValidateTwoThemeDependencies() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php index a4085b0f8ea74b44188f06d1baf97da1239d8f5c..835dc94b5960f2c0ee20fea5ad81f277c7182d06 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php @@ -259,7 +259,3 @@ class TestThemeEngineExtensionList extends ThemeEngineExtensionList { use SettableDiscoveryExtensionListTrait; } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index b68765a8771b195cca96a2acb56c6181a9f1be77..fe2ca19033a90b8cabb450b8ff5c93550fc325ac 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -145,7 +145,3 @@ protected function themeRegistryRebuild() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/RequirementsPageTrait.php b/core/tests/Drupal/Tests/RequirementsPageTrait.php index b71afba0841ca042f37475069214ed241be12756..0c2cc2a114553d806895ded71f528f42291ed656 100644 --- a/core/tests/Drupal/Tests/RequirementsPageTrait.php +++ b/core/tests/Drupal/Tests/RequirementsPageTrait.php @@ -13,7 +13,7 @@ trait RequirementsPageTrait { protected function updateRequirementsProblem() { // Assert a warning is shown on older test environments. $links = $this->getSession()->getPage()->findAll('named', ['link', 'try again']); - if ($links && version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if ($links && version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->assertNoText('Errors found'); $this->assertWarningSummaries(['PHP']); $this->clickLink('try again');