From 94ee839741505ab7c88f738de77fb77478c29011 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Tue, 21 Dec 2021 13:04:58 +0000 Subject: [PATCH] Issue #3255350 by alexpott, longwave: Remove PHP 7 code from Drupal 10 --- .htaccess | 7 --- .../Plugin/VendorHardening/FileSecurity.php | 3 -- .../scaffold/files/example.settings.local.php | 6 +-- core/assets/scaffold/files/htaccess | 7 --- .../Compatibility/Php7/ReflectionClass.php | 48 ------------------ .../Compatibility/Php8/ReflectionClass.php | 50 ------------------- .../Compatibility/ReflectionClass.php | 42 ---------------- .../Doctrine/StaticReflectionClass.php | 20 +++++++- .../Component/FileSecurity/FileSecurity.php | 3 -- .../Drupal/Core/Database/Install/Tasks.php | 2 - core/lib/Drupal/Core/Routing/Router.php | 14 +----- .../Bootstrap/UncaughtExceptionTest.php | 8 +-- .../Core/Database/TransactionTest.php | 4 +- .../MarkupInterfaceComparatorTest.php | 3 +- .../Drupal/Tests/BrowserHtmlDebugTrait.php | 2 +- .../Annotation/Doctrine/DocParserTest.php | 24 --------- .../Drupal/Tests/Core/Config/ConfigTest.php | 7 +-- core/tests/README.md | 1 - sites/example.settings.local.php | 6 +-- 19 files changed, 31 insertions(+), 226 deletions(-) delete mode 100644 core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php7/ReflectionClass.php delete mode 100644 core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php8/ReflectionClass.php delete mode 100644 core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/ReflectionClass.php diff --git a/.htaccess b/.htaccess index 4d19147cc464..7e38f73369cb 100644 --- a/.htaccess +++ b/.htaccess @@ -26,13 +26,6 @@ AddEncoding gzip svgz # sites/default/default.settings.php and # Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be # changed at runtime. - -# PHP 7, Apache 1 and 2. -<IfModule mod_php7.c> - php_value assert.active 0 -</IfModule> - -# PHP 8, Apache 1 and 2. <IfModule mod_php.c> php_value assert.active 0 </IfModule> diff --git a/composer/Plugin/VendorHardening/FileSecurity.php b/composer/Plugin/VendorHardening/FileSecurity.php index 3d168cca925c..cea0685fb358 100644 --- a/composer/Plugin/VendorHardening/FileSecurity.php +++ b/composer/Plugin/VendorHardening/FileSecurity.php @@ -74,9 +74,6 @@ protected static function htaccessPreventExecution() { </Files> # If we know how to do it safely, disable the PHP engine entirely. -<IfModule mod_php7.c> - php_flag engine off -</IfModule> <IfModule mod_php.c> php_flag engine off </IfModule> diff --git a/core/assets/scaffold/files/example.settings.local.php b/core/assets/scaffold/files/example.settings.local.php index 73671ab164bf..1397e9ddf4d7 100644 --- a/core/assets/scaffold/files/example.settings.local.php +++ b/core/assets/scaffold/files/example.settings.local.php @@ -26,9 +26,9 @@ * @see http://php.net/assert * @see https://www.drupal.org/node/2492225 * - * If you are using PHP 7.0 it is strongly recommended that you set - * zend.assertions=1 in the PHP.ini file (It cannot be changed from .htaccess - * or runtime) on development machines and to 0 in production. + * It is strongly recommended that you set zend.assertions=1 in the PHP.ini file + * (It cannot be changed from .htaccess or runtime) on development machines and + * to 0 or -1 in production. * * @see https://wiki.php.net/rfc/expectations */ diff --git a/core/assets/scaffold/files/htaccess b/core/assets/scaffold/files/htaccess index 4d19147cc464..7e38f73369cb 100644 --- a/core/assets/scaffold/files/htaccess +++ b/core/assets/scaffold/files/htaccess @@ -26,13 +26,6 @@ AddEncoding gzip svgz # sites/default/default.settings.php and # Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be # changed at runtime. - -# PHP 7, Apache 1 and 2. -<IfModule mod_php7.c> - php_value assert.active 0 -</IfModule> - -# PHP 8, Apache 1 and 2. <IfModule mod_php.c> php_value assert.active 0 </IfModule> diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php7/ReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php7/ReflectionClass.php deleted file mode 100644 index 8ae2a6750458..000000000000 --- a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php7/ReflectionClass.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php -// phpcs:ignoreFile - -/** - * @file - * - * This class is a near-copy of - * Doctrine\Common\Reflection\Compatibility\Php7\ReflectionClass, which is part - * of the Doctrine project: <http://www.doctrine-project.org>. It was copied - * from version 1.2.2. - * - * Original copyright: - * - * Copyright (c) 2006-2015 Doctrine Project - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -namespace Drupal\Component\Annotation\Doctrine\Compatibility\Php7; - -use ReflectionException; - -trait ReflectionClass -{ - /** - * {@inheritDoc} - */ - public function getConstants() - { - throw new ReflectionException('Method not implemented'); - } - - /** - * {@inheritDoc} - */ - public function newInstance($args) - { - throw new ReflectionException('Method not implemented'); - } -} diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php8/ReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php8/ReflectionClass.php deleted file mode 100644 index 878132062857..000000000000 --- a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/Php8/ReflectionClass.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -// phpcs:ignoreFile - -/** - * @file - * - * This class is a near-copy of - * Doctrine\Common\Reflection\Compatibility\Php8\ReflectionClass, which is part - * of the Doctrine project: <http://www.doctrine-project.org>. It was copied - * from version 1.2.2. - * - * Original copyright: - * - * Copyright (c) 2006-2015 Doctrine Project - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -namespace Drupal\Component\Annotation\Doctrine\Compatibility\Php8; - -use ReflectionException; - -trait ReflectionClass -{ - /** - * {@inheritDoc} - */ - #[\ReturnTypeWillChange] - public function getConstants(?int $filter = null) - { - throw new ReflectionException('Method not implemented'); - } - - /** - * {@inheritDoc} - */ - #[\ReturnTypeWillChange] - public function newInstance(mixed ...$args) - { - throw new ReflectionException('Method not implemented'); - } -} diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/ReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/ReflectionClass.php deleted file mode 100644 index acb5887a72b0..000000000000 --- a/core/lib/Drupal/Component/Annotation/Doctrine/Compatibility/ReflectionClass.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -// phpcs:ignoreFile - -/** - * @file - * - * This class is a near-copy of - * Doctrine\Common\Reflection\Compatibility\ReflectionClass, which is part of - * the Doctrine project: <http://www.doctrine-project.org>. It was copied from - * version 1.2.2. - * - * Original copyright: - * - * Copyright (c) 2006-2015 Doctrine Project - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -namespace Drupal\Component\Annotation\Doctrine\Compatibility; - -use const PHP_VERSION_ID; -use function class_alias; - -if (PHP_VERSION_ID >= 80000) { - class_alias('Drupal\Component\Annotation\Doctrine\Compatibility\Php8\ReflectionClass', 'Drupal\Component\Annotation\Doctrine\Compatibility\ReflectionClass'); -} else { - class_alias('Drupal\Component\Annotation\Doctrine\Compatibility\Php7\ReflectionClass', 'Drupal\Component\Annotation\Doctrine\Compatibility\ReflectionClass'); -} - -if (false) { - class ReflectionClass - { - } -} diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php index 7abdc86b012c..ff8d67f062d1 100644 --- a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php +++ b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php @@ -26,13 +26,11 @@ namespace Drupal\Component\Annotation\Doctrine; -use Drupal\Component\Annotation\Doctrine\Compatibility\ReflectionClass as CompatibilityReflectionClass; use ReflectionClass; use ReflectionException; class StaticReflectionClass extends ReflectionClass { - use CompatibilityReflectionClass; /** * The static reflection parser object. @@ -458,6 +456,24 @@ public function setStaticPropertyValue($name, $value) throw new ReflectionException('Method not implemented'); } + /** + * {@inheritDoc} + */ + #[\ReturnTypeWillChange] + public function getConstants(?int $filter = null) + { + throw new ReflectionException('Method not implemented'); + } + + /** + * {@inheritDoc} + */ + #[\ReturnTypeWillChange] + public function newInstance(mixed ...$args) + { + throw new ReflectionException('Method not implemented'); + } + /** * {@inheritDoc} */ diff --git a/core/lib/Drupal/Component/FileSecurity/FileSecurity.php b/core/lib/Drupal/Component/FileSecurity/FileSecurity.php index aaebcca68024..c21937a8de4f 100644 --- a/core/lib/Drupal/Component/FileSecurity/FileSecurity.php +++ b/core/lib/Drupal/Component/FileSecurity/FileSecurity.php @@ -72,9 +72,6 @@ protected static function htaccessPreventExecution() { </Files> # If we know how to do it safely, disable the PHP engine entirely. -<IfModule mod_php7.c> - php_flag engine off -</IfModule> <IfModule mod_php.c> php_flag engine off </IfModule> diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php index b7fceace1196..abb90e500b3f 100644 --- a/core/lib/Drupal/Core/Database/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Install/Tasks.php @@ -279,8 +279,6 @@ public function getFormOptions(array $database) { ]; global $install_state; - // @todo https://www.drupal.org/project/drupal/issues/3110839 remove PHP 7.4 - // work around and add a better message for the migrate UI. $profile = $install_state['parameters']['profile'] ?? NULL; $db_prefix = ($profile == 'standard') ? 'drupal_' : $profile . '_'; $form['advanced_options']['prefix'] = [ diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php index 87324a68a5b1..23d6ebb66fba 100644 --- a/core/lib/Drupal/Core/Routing/Router.php +++ b/core/lib/Drupal/Core/Routing/Router.php @@ -107,19 +107,7 @@ public function match($pathinfo): array { * {@inheritdoc} */ public function matchRequest(Request $request): array { - try { - $collection = $this->getInitialRouteCollection($request); - } - // PHP 7.4 introduces changes to its serialization format, which mean that - // older versions of PHP are unable to unserialize data that is serialized - // in PHP 7.4. If the site's version of PHP has been downgraded, then - // attempting to unserialize routes from the database will fail, and so the - // router needs to be rebuilt on the current PHP version. - // See https://www.php.net/manual/en/migration74.incompatible.php. - catch (\TypeError $e) { - \Drupal::service('router.builder')->rebuild(); - $collection = $this->getInitialRouteCollection($request); - } + $collection = $this->getInitialRouteCollection($request); if ($collection->count() === 0) { throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $this->currentPath->getPath())); } diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php index 06dde6ce8d09..a65210607c0a 100644 --- a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php +++ b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php @@ -94,9 +94,7 @@ public function testUncaughtException() { public function testUncaughtFatalError() { $fatal_error = [ '%type' => 'TypeError', - '@message' => PHP_VERSION_ID >= 80000 ? - 'Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}(): Argument #1 ($test) must be of type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65' : - 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65', + '@message' => 'Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}(): Argument #1 ($test) must be of type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65', '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()', ]; $this->drupalGet('error-test/generate-fatals'); @@ -178,9 +176,7 @@ public function testErrorContainer() { $this->writeSettings($settings); \Drupal::service('kernel')->invalidateContainer(); - $this->expectedExceptionMessage = PHP_VERSION_ID >= 80000 ? - 'Drupal\FunctionalTests\Bootstrap\ErrorContainer::Drupal\FunctionalTests\Bootstrap\{closure}(): Argument #1 ($container) must be of type Drupal\FunctionalTests\Bootstrap\ErrorContainer' : - 'Argument 1 passed to Drupal\FunctionalTests\Bootstrap\ErrorContainer::Drupal\FunctionalTests\Bootstrap\{closur'; + $this->expectedExceptionMessage = 'Drupal\FunctionalTests\Bootstrap\ErrorContainer::Drupal\FunctionalTests\Bootstrap\{closure}(): Argument #1 ($container) must be of type Drupal\FunctionalTests\Bootstrap\ErrorContainer'; $this->drupalGet(''); $this->assertSession()->statusCodeEquals(500); diff --git a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php index e76618152a62..7aa37c70ef8b 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php @@ -264,9 +264,7 @@ public function testTransactionWithDdlStatement() { // Rollback the outer transaction. $transaction->rollBack(); // @see \Drupal\Core\Database\Driver\mysql\Connection::rollBack() - if (PHP_VERSION_ID >= 80000) { - $this->fail('Rolling back a transaction containing DDL should produce a warning.'); - } + $this->fail('Rolling back a transaction containing DDL should produce a warning.'); } catch (Warning $warning) { $this->assertSame('Rollback attempted when there is no active transaction. This can cause data integrity issues.', $warning->getMessage()); diff --git a/core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php b/core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php index bc8685db01f2..f3008e694e4e 100644 --- a/core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php +++ b/core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php @@ -6,7 +6,6 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; -use PHPUnit\Framework\Error\Notice; use PHPUnit\Framework\Error\Warning; use SebastianBergmann\Comparator\Factory; use SebastianBergmann\Comparator\ComparisonFailure; @@ -109,7 +108,7 @@ public function dataSetProvider() { new FormattableMarkup('goldfinger', []), ['goldfinger'], FALSE, - PHP_VERSION_ID >= 80000 ? Warning::class : Notice::class, + Warning::class, ], 'stdClass vs TranslatableMarkup' => [ (object) ['goldfinger'], diff --git a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php index 4288598a592a..e0b85ef5460f 100644 --- a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php +++ b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php @@ -180,7 +180,7 @@ protected function getResponseLogHandler() { $html_output .= '<hr />' . $request->getMethod() . ' request to: ' . $request->getUri(); // Get the response body as a string. Any errors are silenced as - // tests should not fail if there is a problem. On PHP 7.4 + // tests should not fail if there is a problem. // \Drupal\Tests\migrate\Functional\process\DownloadFunctionalTest // fails without the usage of a silence operator. $body = @(string) $response->getBody(); diff --git a/core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php b/core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php index 5a028bcb4ffe..d05e46585677 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php @@ -1189,30 +1189,6 @@ public function testCastNegativeFloat() $this->assertIsFloat($annot->value); } - public function testReservedKeywordsInAnnotations() - { - if (PHP_VERSION_ID >= 70000) { - $this->markTestSkipped('This test requires PHP 5.6 or lower.'); - } - require 'ReservedKeywordsClasses.php'; - - $parser = $this->createTestParser(); - - $result = $parser->parse('@Drupal\Tests\Component\Annotation\Doctrine\True'); - $this->assertInstanceOf(True::class, $result[0]); - $result = $parser->parse('@Drupal\Tests\Component\Annotation\Doctrine\False'); - $this->assertInstanceOf(False::class, $result[0]); - $result = $parser->parse('@Drupal\Tests\Component\Annotation\Doctrine\Null'); - $this->assertInstanceOf(Null::class, $result[0]); - - $result = $parser->parse('@True'); - $this->assertInstanceOf(True::class, $result[0]); - $result = $parser->parse('@False'); - $this->assertInstanceOf(False::class, $result[0]); - $result = $parser->parse('@Null'); - $this->assertInstanceOf(Null::class, $result[0]); - } - public function testSetValuesException() { $this->expectException('\Doctrine\Common\Annotations\AnnotationException'); diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index d7b6ee5f0e80..51f3c2d9a85c 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -269,12 +269,7 @@ public function testSetIllegalOffsetValue() { $this->config->set('testData', 1); // Attempt to treat the single value as a nested item. - if (PHP_VERSION_ID >= 80000) { - $this->expectError(); - } - else { - $this->expectWarning(); - } + $this->expectError(); $this->config->set('testData.illegalOffset', 1); } diff --git a/core/tests/README.md b/core/tests/README.md index f88289f48ccc..36655e3f123d 100644 --- a/core/tests/README.md +++ b/core/tests/README.md @@ -42,7 +42,6 @@ to install the following additional software: * Google Chrome or Chromium browser * chromedriver (tested with version 2.45) -- see https://sites.google.com/chromium.org/driver/ -* PHP 7.1 or higher ## Running tests diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php index 73671ab164bf..1397e9ddf4d7 100644 --- a/sites/example.settings.local.php +++ b/sites/example.settings.local.php @@ -26,9 +26,9 @@ * @see http://php.net/assert * @see https://www.drupal.org/node/2492225 * - * If you are using PHP 7.0 it is strongly recommended that you set - * zend.assertions=1 in the PHP.ini file (It cannot be changed from .htaccess - * or runtime) on development machines and to 0 in production. + * It is strongly recommended that you set zend.assertions=1 in the PHP.ini file + * (It cannot be changed from .htaccess or runtime) on development machines and + * to 0 or -1 in production. * * @see https://wiki.php.net/rfc/expectations */ -- GitLab