From 0d091ad962fccade50bfcb38cce2acad5c70f07c Mon Sep 17 00:00:00 2001 From: Lauri Eskola Date: Wed, 31 Aug 2022 21:07:03 +0300 Subject: [PATCH] Issue #3258987 by phenaproxima, xjm, mrweiner, catch, cilefen, mfb, benjifisher, Berdir, szato: Status report should warn about OPcache bug in PHP 8.1.0 to 8.1.5 --- core/modules/system/system.install | 13 +++++++++++++ .../src/Functional/System/PhpRequirementTest.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/modules/system/system.install b/core/modules/system/system.install index cfa0966abbc..15b4f485877 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -316,6 +316,19 @@ function system_requirements($phase) { 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 PHP\'s version support documentation and the Drupal PHP requirements page for more information.', ['%recommended' => \Drupal::RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/system-requirements/php-requirements']); $requirements['php']['severity'] = REQUIREMENT_INFO; + + // PHP 8.1.0 through 8.1.5 have a known OPcache bug that can cause fatal + // errors, so warn about that when running Drupal on those versions. + // @todo Remove this when \Drupal::MINIMUM_PHP is at least 8.1.6 in + // https://www.drupal.org/i/3305726. + if (version_compare(\Drupal::MINIMUM_PHP, '8.1.6') < 0) { + $requirements['php']['description'] = t('PHP %version has an OPcache bug that can cause fatal errors with class autoloading. This can be fixed by upgrading to PHP 8.1.6 or later. See PHP\'s version support documentation and the Drupal PHP requirements page for more information.', [ + '%version' => $phpversion, + ':bug_url' => 'https://github.com/php/php-src/issues/8164', + ':php_requirements' => 'https://www.drupal.org/docs/system-requirements/php-requirements', + ]); + $requirements['php']['severity'] = REQUIREMENT_WARNING; + } } // Test for PHP extensions. diff --git a/core/modules/system/tests/src/Functional/System/PhpRequirementTest.php b/core/modules/system/tests/src/Functional/System/PhpRequirementTest.php index dfb63bee495..905087ffc24 100644 --- a/core/modules/system/tests/src/Functional/System/PhpRequirementTest.php +++ b/core/modules/system/tests/src/Functional/System/PhpRequirementTest.php @@ -72,7 +72,17 @@ class PhpRequirementTest extends BrowserTestBase { // There should be an informational message if the PHP version is below the // recommended version. if (version_compare($phpversion, \Drupal::RECOMMENDED_PHP) < 0) { - $this->assertSession()->pageTextContains('It is recommended to upgrade to PHP version ' . \Drupal::RECOMMENDED_PHP . ' or higher'); + // If it's possible to run Drupal on PHP 8.1.0 to 8.1.5, warn about a + // bug in OPcache. + // @todo Remove this when \Drupal::MINIMUM_PHP is at least 8.1.6 in + // https://www.drupal.org/i/3305726. + if (version_compare(\Drupal::MINIMUM_PHP, '8.1.6') < 0) { + $this->assertSession()->pageTextContains("PHP $phpversion has an OPcache bug that can cause fatal errors with class autoloading. This can be fixed by upgrading to PHP 8.1.6 or later."); + $this->assertSession()->linkExists('an OPcache bug that can cause fatal errors with class autoloading'); + } + else { + $this->assertSession()->pageTextContains('It is recommended to upgrade to PHP version ' . \Drupal::RECOMMENDED_PHP . ' or higher'); + } } // Otherwise, the message should not be there. else {