From c5c85f184d27c5218e5f83fc34cea2cc7a571f95 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Tue, 5 Mar 2024 23:11:18 +0000
Subject: [PATCH] Revert "Issue #3425337 by mondrake: Fix root namespace
 classes DebugClassLoader forward compatibility warnings"

This reverts commit ea9cc7538b80c29f56324a4a115d263d1a635816.
---
 .../Operations/ScaffoldFileCollection.php     |   3 +-
 core/.deprecation-ignore.txt                  |   4 +
 .../Doctrine/StaticReflectionClass.php        | 138 ++++++++++++------
 .../FileSystem/RegexDirectoryIterator.php     |   3 +-
 .../Component/Plugin/LazyPluginCollection.php |   6 +-
 .../Component/Render/HtmlEscapedText.php      |   6 +-
 .../Core/Config/Schema/ArrayElement.php       |   3 +-
 .../Drupal/Core/Database/Query/Condition.php  |   3 +-
 .../Core/Database/Query/InsertTrait.php       |   3 +-
 .../Drupal/Core/Entity/ContentEntityBase.php  |   3 +-
 .../Plugin/DataType/ConfigEntityAdapter.php   |   3 +-
 .../Entity/Plugin/DataType/EntityAdapter.php  |   3 +-
 core/lib/Drupal/Core/GeneratedLink.php        |   6 +-
 .../Core/Session/WriteSafeSessionHandler.php  |  18 ++-
 core/lib/Drupal/Core/Template/Attribute.php   |  19 ++-
 .../Drupal/Core/Template/AttributeArray.php   |  15 +-
 .../Core/TypedData/ComputedItemListTrait.php  |   9 +-
 .../Drupal/Core/TypedData/DataDefinition.php  |  12 +-
 .../TypedData/Plugin/DataType/ItemList.php    |  18 ++-
 .../Core/TypedData/Plugin/DataType/Map.php    |   3 +-
 .../comment/src/CommentFieldItemList.php      |   3 +-
 .../SectionStorage/SectionStorageBase.php     |   3 +-
 .../layout_builder/src/SectionListTrait.php   |   3 +-
 .../migrate/src/Plugin/migrate/id_map/Sql.php |  15 +-
 .../migrate/source/SourcePluginBase.php       |  15 +-
 .../tests/src/Unit/MigrateExecutableTest.php  |   3 +-
 core/tests/Drupal/Tests/StreamCapturer.php    |   3 +-
 27 files changed, 216 insertions(+), 107 deletions(-)

diff --git a/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php b/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php
index c6e89ef4c791..a1bacf597d77 100644
--- a/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php
+++ b/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php
@@ -115,7 +115,8 @@ protected function checkListHasItemWithContent(array $scaffold_files) {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->scaffoldFilesByProject);
   }
 
diff --git a/core/.deprecation-ignore.txt b/core/.deprecation-ignore.txt
index 1650f6f8a8b6..6198b95d4e57 100644
--- a/core/.deprecation-ignore.txt
+++ b/core/.deprecation-ignore.txt
@@ -19,6 +19,10 @@
 %Method "Twig\\TokenParser\\TokenParserInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
 %Method "WebDriver\\Service\\CurlServiceInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in implementation "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
 
+# Skip root namespace native DebugClassLoader forward compatibility warnings.
+# These mostly refer to PHP native classes, could be fixed for PHP 8.1.
+%Method "[^\\]+::\w+\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
+
 # The following deprecation is listed for Twig 2 compatibility when unit
 # testing using \Symfony\Component\ErrorHandler\DebugClassLoader.
 %The "Twig\\Environment::getTemplateClass\(\)" method is considered internal\. It may change without further notice\. You should not extend it from "Drupal\\Core\\Template\\TwigEnvironment"\.%
diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php
index 87acb3dd4002..b0e60706962a 100644
--- a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php
+++ b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php
@@ -47,7 +47,8 @@ public function __construct(StaticReflectionParser $staticReflectionParser)
     /**
      * {@inheritDoc}
      */
-    public function getName(): string
+    #[\ReturnTypeWillChange]
+    public function getName()
     {
         return $this->staticReflectionParser->getClassName();
     }
@@ -55,7 +56,8 @@ public function getName(): string
     /**
      * {@inheritDoc}
      */
-    public function getDocComment(): string|FALSE
+    #[\ReturnTypeWillChange]
+    public function getDocComment()
     {
         return $this->staticReflectionParser->getDocComment();
     }
@@ -63,7 +65,8 @@ public function getDocComment(): string|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getNamespaceName(): string
+    #[\ReturnTypeWillChange]
+    public function getNamespaceName()
     {
         return $this->staticReflectionParser->getNamespaceName();
     }
@@ -91,7 +94,8 @@ public function hasClassAttribute(string $attribute)
     /**
      * {@inheritDoc}
      */
-    public function getMethod($name): \ReflectionMethod
+    #[\ReturnTypeWillChange]
+    public function getMethod($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -99,7 +103,8 @@ public function getMethod($name): \ReflectionMethod
     /**
      * {@inheritDoc}
      */
-    public function getProperty($name): \ReflectionProperty
+    #[\ReturnTypeWillChange]
+    public function getProperty($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -115,7 +120,8 @@ public static function export($argument, $return = false)
     /**
      * {@inheritDoc}
      */
-    public function getConstant($name): mixed
+    #[\ReturnTypeWillChange]
+    public function getConstant($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -123,7 +129,8 @@ public function getConstant($name): mixed
     /**
      * {@inheritDoc}
      */
-    public function getConstructor(): ?\ReflectionMethod
+    #[\ReturnTypeWillChange]
+    public function getConstructor()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -131,7 +138,8 @@ public function getConstructor(): ?\ReflectionMethod
     /**
      * {@inheritDoc}
      */
-    public function getDefaultProperties(): array
+    #[\ReturnTypeWillChange]
+    public function getDefaultProperties()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -139,7 +147,8 @@ public function getDefaultProperties(): array
     /**
      * {@inheritDoc}
      */
-    public function getEndLine(): int|FALSE
+    #[\ReturnTypeWillChange]
+    public function getEndLine()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -147,7 +156,8 @@ public function getEndLine(): int|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getExtension(): ?\ReflectionExtension
+    #[\ReturnTypeWillChange]
+    public function getExtension()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -155,7 +165,8 @@ public function getExtension(): ?\ReflectionExtension
     /**
      * {@inheritDoc}
      */
-    public function getExtensionName(): string|FALSE
+    #[\ReturnTypeWillChange]
+    public function getExtensionName()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -163,7 +174,8 @@ public function getExtensionName(): string|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getFileName(): string|FALSE
+    #[\ReturnTypeWillChange]
+    public function getFileName()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -171,7 +183,8 @@ public function getFileName(): string|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getInterfaceNames(): array
+    #[\ReturnTypeWillChange]
+    public function getInterfaceNames()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -179,7 +192,8 @@ public function getInterfaceNames(): array
     /**
      * {@inheritDoc}
      */
-    public function getInterfaces(): array
+    #[\ReturnTypeWillChange]
+    public function getInterfaces()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -187,7 +201,8 @@ public function getInterfaces(): array
     /**
      * {@inheritDoc}
      */
-    public function getMethods($filter = null): array
+    #[\ReturnTypeWillChange]
+    public function getMethods($filter = null)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -195,7 +210,8 @@ public function getMethods($filter = null): array
     /**
      * {@inheritDoc}
      */
-    public function getModifiers(): int
+    #[\ReturnTypeWillChange]
+    public function getModifiers()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -203,7 +219,8 @@ public function getModifiers(): int
     /**
      * {@inheritDoc}
      */
-    public function getParentClass(): \ReflectionClass|FALSE
+    #[\ReturnTypeWillChange]
+    public function getParentClass()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -211,7 +228,8 @@ public function getParentClass(): \ReflectionClass|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getProperties($filter = null): array
+    #[\ReturnTypeWillChange]
+    public function getProperties($filter = null)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -219,7 +237,8 @@ public function getProperties($filter = null): array
     /**
      * {@inheritDoc}
      */
-    public function getShortName(): string
+    #[\ReturnTypeWillChange]
+    public function getShortName()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -227,7 +246,8 @@ public function getShortName(): string
     /**
      * {@inheritDoc}
      */
-    public function getStartLine(): int|FALSE
+    #[\ReturnTypeWillChange]
+    public function getStartLine()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -235,7 +255,8 @@ public function getStartLine(): int|FALSE
     /**
      * {@inheritDoc}
      */
-    public function getStaticProperties(): ?array
+    #[\ReturnTypeWillChange]
+    public function getStaticProperties()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -243,7 +264,8 @@ public function getStaticProperties(): ?array
     /**
      * {@inheritDoc}
      */
-    public function getStaticPropertyValue($name, $default = ''): mixed
+    #[\ReturnTypeWillChange]
+    public function getStaticPropertyValue($name, $default = '')
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -251,7 +273,8 @@ public function getStaticPropertyValue($name, $default = ''): mixed
     /**
      * {@inheritDoc}
      */
-    public function getTraitAliases(): array
+    #[\ReturnTypeWillChange]
+    public function getTraitAliases()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -259,7 +282,8 @@ public function getTraitAliases(): array
     /**
      * {@inheritDoc}
      */
-    public function getTraitNames(): array
+    #[\ReturnTypeWillChange]
+    public function getTraitNames()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -267,7 +291,8 @@ public function getTraitNames(): array
     /**
      * {@inheritDoc}
      */
-    public function getTraits(): array
+    #[\ReturnTypeWillChange]
+    public function getTraits()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -275,7 +300,8 @@ public function getTraits(): array
     /**
      * {@inheritDoc}
      */
-    public function hasConstant($name): bool
+    #[\ReturnTypeWillChange]
+    public function hasConstant($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -283,7 +309,8 @@ public function hasConstant($name): bool
     /**
      * {@inheritDoc}
      */
-    public function hasMethod($name): bool
+    #[\ReturnTypeWillChange]
+    public function hasMethod($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -291,7 +318,8 @@ public function hasMethod($name): bool
     /**
      * {@inheritDoc}
      */
-    public function hasProperty($name): bool
+    #[\ReturnTypeWillChange]
+    public function hasProperty($name)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -299,7 +327,8 @@ public function hasProperty($name): bool
     /**
      * {@inheritDoc}
      */
-    public function implementsInterface($interface): bool
+    #[\ReturnTypeWillChange]
+    public function implementsInterface($interface)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -307,7 +336,8 @@ public function implementsInterface($interface): bool
     /**
      * {@inheritDoc}
      */
-    public function inNamespace(): bool
+    #[\ReturnTypeWillChange]
+    public function inNamespace()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -315,7 +345,8 @@ public function inNamespace(): bool
     /**
      * {@inheritDoc}
      */
-    public function isAbstract(): bool
+    #[\ReturnTypeWillChange]
+    public function isAbstract()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -323,7 +354,8 @@ public function isAbstract(): bool
     /**
      * {@inheritDoc}
      */
-    public function isCloneable(): bool
+    #[\ReturnTypeWillChange]
+    public function isCloneable()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -331,7 +363,8 @@ public function isCloneable(): bool
     /**
      * {@inheritDoc}
      */
-    public function isFinal(): bool
+    #[\ReturnTypeWillChange]
+    public function isFinal()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -339,7 +372,8 @@ public function isFinal(): bool
     /**
      * {@inheritDoc}
      */
-    public function isInstance($object): bool
+    #[\ReturnTypeWillChange]
+    public function isInstance($object)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -347,7 +381,8 @@ public function isInstance($object): bool
     /**
      * {@inheritDoc}
      */
-    public function isInstantiable(): bool
+    #[\ReturnTypeWillChange]
+    public function isInstantiable()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -355,7 +390,8 @@ public function isInstantiable(): bool
     /**
      * {@inheritDoc}
      */
-    public function isInterface(): bool
+    #[\ReturnTypeWillChange]
+    public function isInterface()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -363,7 +399,8 @@ public function isInterface(): bool
     /**
      * {@inheritDoc}
      */
-    public function isInternal(): bool
+    #[\ReturnTypeWillChange]
+    public function isInternal()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -371,7 +408,8 @@ public function isInternal(): bool
     /**
      * {@inheritDoc}
      */
-    public function isIterateable(): bool
+    #[\ReturnTypeWillChange]
+    public function isIterateable()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -379,7 +417,8 @@ public function isIterateable(): bool
     /**
      * {@inheritDoc}
      */
-    public function isSubclassOf($class): bool
+    #[\ReturnTypeWillChange]
+    public function isSubclassOf($class)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -387,7 +426,8 @@ public function isSubclassOf($class): bool
     /**
      * {@inheritDoc}
      */
-    public function isTrait(): bool
+    #[\ReturnTypeWillChange]
+    public function isTrait()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -395,7 +435,8 @@ public function isTrait(): bool
     /**
      * {@inheritDoc}
      */
-    public function isUserDefined(): bool
+    #[\ReturnTypeWillChange]
+    public function isUserDefined()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -403,7 +444,8 @@ public function isUserDefined(): bool
     /**
      * {@inheritDoc}
      */
-    public function newInstanceArgs(array $args = []): ?object
+    #[\ReturnTypeWillChange]
+    public function newInstanceArgs(array $args = [])
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -411,7 +453,8 @@ public function newInstanceArgs(array $args = []): ?object
     /**
      * {@inheritDoc}
      */
-    public function newInstanceWithoutConstructor(): object
+    #[\ReturnTypeWillChange]
+    public function newInstanceWithoutConstructor()
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -419,7 +462,8 @@ public function newInstanceWithoutConstructor(): object
     /**
      * {@inheritDoc}
      */
-    public function setStaticPropertyValue($name, $value): void
+    #[\ReturnTypeWillChange]
+    public function setStaticPropertyValue($name, $value)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -427,7 +471,8 @@ public function setStaticPropertyValue($name, $value): void
     /**
      * {@inheritDoc}
      */
-    public function getConstants(?int $filter = null): array
+    #[\ReturnTypeWillChange]
+    public function getConstants(?int $filter = null)
     {
         throw new ReflectionException('Method not implemented');
     }
@@ -435,7 +480,8 @@ public function getConstants(?int $filter = null): array
     /**
      * {@inheritDoc}
      */
-    public function newInstance(mixed ...$args): object
+    #[\ReturnTypeWillChange]
+    public function newInstance(mixed ...$args)
     {
         throw new ReflectionException('Method not implemented');
     }
diff --git a/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php b/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php
index cc17aa643c5e..cfa616ae1bf5 100644
--- a/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php
+++ b/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php
@@ -23,7 +23,8 @@ public function __construct($path, $regex) {
   /**
    * Implements \RegexIterator::accept().
    */
-  public function accept(): bool {
+  #[\ReturnTypeWillChange]
+  public function accept() {
     /** @var \SplFileInfo $file_info */
     $file_info = $this->getInnerIterator()->current();
     return $file_info->isFile() && preg_match($this->getRegex(), $file_info->getFilename());
diff --git a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php
index db5b8755051c..6574c5b3daec 100644
--- a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php
+++ b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php
@@ -142,7 +142,8 @@ public function removeInstanceId($instance_id) {
     $this->remove($instance_id);
   }
 
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     $instances = [];
     foreach ($this->getInstanceIds() as $instance_id) {
       $instances[$instance_id] = $this->get($instance_id);
@@ -153,7 +154,8 @@ public function getIterator(): \ArrayIterator {
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return count($this->instanceIds);
   }
 
diff --git a/core/lib/Drupal/Component/Render/HtmlEscapedText.php b/core/lib/Drupal/Component/Render/HtmlEscapedText.php
index 6ca9538089e6..d5121bfb9f28 100644
--- a/core/lib/Drupal/Component/Render/HtmlEscapedText.php
+++ b/core/lib/Drupal/Component/Render/HtmlEscapedText.php
@@ -41,14 +41,16 @@ public function __toString() {
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return mb_strlen($this->string);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function jsonSerialize(): string {
+  #[\ReturnTypeWillChange]
+  public function jsonSerialize() {
     return $this->__toString();
   }
 
diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
index 11fc9aca2414..e9e4998010bd 100644
--- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
+++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
@@ -114,7 +114,8 @@ public function onChange($name) {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->getElements());
   }
 
diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php
index 377d45cb59d5..fcd0b5dfba30 100644
--- a/core/lib/Drupal/Core/Database/Query/Condition.php
+++ b/core/lib/Drupal/Core/Database/Query/Condition.php
@@ -90,7 +90,8 @@ public function __construct($conjunction) {
    * size of its conditional array minus one, because one element is the
    * conjunction.
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return count($this->conditions) - 1;
   }
 
diff --git a/core/lib/Drupal/Core/Database/Query/InsertTrait.php b/core/lib/Drupal/Core/Database/Query/InsertTrait.php
index 808c9f53a117..a429c88eead6 100644
--- a/core/lib/Drupal/Core/Database/Query/InsertTrait.php
+++ b/core/lib/Drupal/Core/Database/Query/InsertTrait.php
@@ -179,7 +179,8 @@ protected function getInsertPlaceholderFragment(array $nested_insert_values, arr
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return count($this->insertValues);
   }
 
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 5371bdfd1655..52b967425676 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -687,7 +687,8 @@ public function getTranslatableFields($include_computed = TRUE) {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->getFields());
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
index 46c15afc72a8..a30106029fcb 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
@@ -69,7 +69,8 @@ public function onChange($property_name) {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     if (isset($this->entity)) {
       return $this->getConfigTypedData()->getIterator();
     }
diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
index 154c1c4e083b..602278487e40 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
@@ -162,7 +162,8 @@ public function applyDefaultValue($notify = TRUE) {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return $this->entity instanceof \IteratorAggregate ? $this->entity->getIterator() : new \ArrayIterator([]);
   }
 
diff --git a/core/lib/Drupal/Core/GeneratedLink.php b/core/lib/Drupal/Core/GeneratedLink.php
index 7bebcbaf31d8..0c484836f11f 100644
--- a/core/lib/Drupal/Core/GeneratedLink.php
+++ b/core/lib/Drupal/Core/GeneratedLink.php
@@ -58,14 +58,16 @@ public function __toString() {
   /**
    * {@inheritdoc}
    */
-  public function jsonSerialize(): string {
+  #[\ReturnTypeWillChange]
+  public function jsonSerialize() {
     return $this->__toString();
   }
 
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return mb_strlen($this->__toString());
   }
 
diff --git a/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
index 3c1f61ece10a..d18340d754b7 100644
--- a/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
+++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
@@ -43,35 +43,40 @@ public function __construct(\SessionHandlerInterface $wrapped_session_handler, $
   /**
    * {@inheritdoc}
    */
-  public function close(): bool {
+  #[\ReturnTypeWillChange]
+  public function close() {
     return $this->wrappedSessionHandler->close();
   }
 
   /**
    * {@inheritdoc}
    */
-  public function destroy($session_id): bool {
+  #[\ReturnTypeWillChange]
+  public function destroy($session_id) {
     return $this->wrappedSessionHandler->destroy($session_id);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function gc($max_lifetime): int|FALSE {
+  #[\ReturnTypeWillChange]
+  public function gc($max_lifetime) {
     return $this->wrappedSessionHandler->gc($max_lifetime);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function open($save_path, $session_id): bool {
+  #[\ReturnTypeWillChange]
+  public function open($save_path, $session_id) {
     return $this->wrappedSessionHandler->open($save_path, $session_id);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function read($session_id): string|FALSE {
+  #[\ReturnTypeWillChange]
+  public function read($session_id) {
     $value = $this->wrappedSessionHandler->read($session_id);
     $this->readSessions[$session_id] = $value;
     return $value;
@@ -80,7 +85,8 @@ public function read($session_id): string|FALSE {
   /**
    * {@inheritdoc}
    */
-  public function write($session_id, $session_data): bool {
+  #[\ReturnTypeWillChange]
+  public function write($session_id, $session_data) {
     // Only write the session when it has been modified.
     if (isset($this->readSessions[$session_id]) && $this->readSessions[$session_id] === $session_data) {
       return TRUE;
diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php
index a08fdafd17c2..6a6759d1dbad 100644
--- a/core/lib/Drupal/Core/Template/Attribute.php
+++ b/core/lib/Drupal/Core/Template/Attribute.php
@@ -90,17 +90,18 @@ public function __construct($attributes = []) {
   /**
    * {@inheritdoc}
    */
-  public function offsetGet($name): mixed {
+  #[\ReturnTypeWillChange]
+  public function offsetGet($name) {
     if (isset($this->storage[$name])) {
       return $this->storage[$name];
     }
-    return NULL;
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetSet($name, $value): void {
+  #[\ReturnTypeWillChange]
+  public function offsetSet($name, $value) {
     $this->storage[$name] = $this->createAttributeValue($name, $value);
   }
 
@@ -153,14 +154,16 @@ protected function createAttributeValue($name, $value) {
   /**
    * {@inheritdoc}
    */
-  public function offsetUnset($name): void {
+  #[\ReturnTypeWillChange]
+  public function offsetUnset($name) {
     unset($this->storage[$name]);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetExists($name): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($name) {
     return isset($this->storage[$name]);
   }
 
@@ -355,7 +358,8 @@ public function __clone() {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->storage);
   }
 
@@ -372,7 +376,8 @@ public function storage() {
    * @return string
    *   The safe string content.
    */
-  public function jsonSerialize(): string {
+  #[\ReturnTypeWillChange]
+  public function jsonSerialize() {
     return (string) $this;
   }
 
diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php
index 2f003f2de6e4..71127f00471d 100644
--- a/core/lib/Drupal/Core/Template/AttributeArray.php
+++ b/core/lib/Drupal/Core/Template/AttributeArray.php
@@ -35,14 +35,16 @@ class AttributeArray extends AttributeValueBase implements \ArrayAccess, \Iterat
   /**
    * {@inheritdoc}
    */
-  public function offsetGet($offset): mixed {
+  #[\ReturnTypeWillChange]
+  public function offsetGet($offset) {
     return $this->value[$offset];
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetSet($offset, $value): void {
+  #[\ReturnTypeWillChange]
+  public function offsetSet($offset, $value) {
     if (isset($offset)) {
       $this->value[$offset] = $value;
     }
@@ -54,14 +56,16 @@ public function offsetSet($offset, $value): void {
   /**
    * {@inheritdoc}
    */
-  public function offsetUnset($offset): void {
+  #[\ReturnTypeWillChange]
+  public function offsetUnset($offset) {
     unset($this->value[$offset]);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetExists($offset): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($offset) {
     return isset($this->value[$offset]);
   }
 
@@ -77,7 +81,8 @@ public function __toString() {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->value);
   }
 
diff --git a/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php b/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php
index 8e31e3d1c629..f1d4d4236b2e 100644
--- a/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php
+++ b/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php
@@ -118,7 +118,8 @@ public function isEmpty() {
   /**
    * {@inheritdoc}
    */
-  public function offsetExists($offset): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($offset) {
     $this->ensureComputedValue();
     return parent::offsetExists($offset);
   }
@@ -126,7 +127,8 @@ public function offsetExists($offset): bool {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     $this->ensureComputedValue();
     return parent::getIterator();
   }
@@ -134,7 +136,8 @@ public function getIterator(): \ArrayIterator {
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     $this->ensureComputedValue();
     return parent::count();
   }
diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php
index a00adefe1c48..a82f819b4cde 100644
--- a/core/lib/Drupal/Core/TypedData/DataDefinition.php
+++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php
@@ -314,7 +314,8 @@ public function addConstraint($constraint_name, $options = NULL) {
    * This is for BC support only.
    * @todo: Remove in https://www.drupal.org/node/1928868.
    */
-  public function offsetExists($offset): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($offset) {
     // PHP's array access does not work correctly with isset(), so we have to
     // bake isset() in here. See https://bugs.php.net/bug.php?id=41727.
     return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]);
@@ -326,7 +327,8 @@ public function offsetExists($offset): bool {
    * This is for BC support only.
    * @todo: Remove in https://www.drupal.org/node/1928868.
    */
-  public function &offsetGet($offset): mixed {
+  #[\ReturnTypeWillChange]
+  public function &offsetGet($offset) {
     if (!isset($this->definition[$offset])) {
       $this->definition[$offset] = NULL;
     }
@@ -339,7 +341,8 @@ public function &offsetGet($offset): mixed {
    * This is for BC support only.
    * @todo: Remove in https://www.drupal.org/node/1928868.
    */
-  public function offsetSet($offset, $value): void {
+  #[\ReturnTypeWillChange]
+  public function offsetSet($offset, $value) {
     $this->definition[$offset] = $value;
   }
 
@@ -349,7 +352,8 @@ public function offsetSet($offset, $value): void {
    * This is for BC support only.
    * @todo: Remove in https://www.drupal.org/node/1928868.
    */
-  public function offsetUnset($offset): void {
+  #[\ReturnTypeWillChange]
+  public function offsetUnset($offset) {
     unset($this->definition[$offset]);
   }
 
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
index ee648a50f86f..0e6a377bc678 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
@@ -170,7 +170,8 @@ public function first() {
   /**
    * {@inheritdoc}
    */
-  public function offsetExists($offset): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($offset) {
     // We do not want to throw exceptions here, so we do not use get().
     return isset($this->list[$offset]);
   }
@@ -178,21 +179,24 @@ public function offsetExists($offset): bool {
   /**
    * {@inheritdoc}
    */
-  public function offsetUnset($offset): void {
+  #[\ReturnTypeWillChange]
+  public function offsetUnset($offset) {
     $this->removeItem($offset);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetGet($offset): mixed {
+  #[\ReturnTypeWillChange]
+  public function offsetGet($offset) {
     return $this->get($offset);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function offsetSet($offset, $value): void {
+  #[\ReturnTypeWillChange]
+  public function offsetSet($offset, $value) {
     if (!isset($offset)) {
       // The [] operator has been used.
       $this->appendItem($value);
@@ -231,14 +235,16 @@ public function getItemDefinition() {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->list);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return count($this->list);
   }
 
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php
index e08e9312e0c7..e216ceb77571 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php
@@ -183,7 +183,8 @@ public function toArray() {
   /**
    * {@inheritdoc}
    */
-  public function getIterator(): \ArrayIterator {
+  #[\ReturnTypeWillChange]
+  public function getIterator() {
     return new \ArrayIterator($this->getProperties());
   }
 
diff --git a/core/modules/comment/src/CommentFieldItemList.php b/core/modules/comment/src/CommentFieldItemList.php
index 53420df3e78b..985f8652250d 100644
--- a/core/modules/comment/src/CommentFieldItemList.php
+++ b/core/modules/comment/src/CommentFieldItemList.php
@@ -30,7 +30,8 @@ public function get($index) {
   /**
    * {@inheritdoc}
    */
-  public function offsetExists($offset): bool {
+  #[\ReturnTypeWillChange]
+  public function offsetExists($offset) {
     // For consistency with what happens in get(), we force offsetExists() to
     // be TRUE for delta 0.
     if ($offset === 0) {
diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php
index 3f9d07c860d5..93f8637a564a 100644
--- a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php
+++ b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php
@@ -38,7 +38,8 @@ public function getStorageType() {
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     return $this->getSectionList()->count();
   }
 
diff --git a/core/modules/layout_builder/src/SectionListTrait.php b/core/modules/layout_builder/src/SectionListTrait.php
index 7a049dec6c40..3a2947b99e18 100644
--- a/core/modules/layout_builder/src/SectionListTrait.php
+++ b/core/modules/layout_builder/src/SectionListTrait.php
@@ -25,7 +25,8 @@ abstract protected function setSections(array $sections);
   /**
    * {@inheritdoc}
    */
-  public function count(): int {
+  #[\ReturnTypeWillChange]
+  public function count() {
     if ($this->hasBlankSection()) {
       return 0;
     }
diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
index b9261d098943..54d55cfb0332 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -913,7 +913,8 @@ public function destroy() {
    *
    * This is called before beginning a foreach loop.
    */
-  public function rewind(): void {
+  #[\ReturnTypeWillChange]
+  public function rewind() {
     $this->currentRow = NULL;
     $fields = [];
     foreach ($this->sourceIdFields() as $field) {
@@ -934,7 +935,8 @@ public function rewind(): void {
    *
    * This is called when entering a loop iteration, returning the current row.
    */
-  public function current(): mixed {
+  #[\ReturnTypeWillChange]
+  public function current() {
     return $this->currentRow;
   }
 
@@ -945,7 +947,8 @@ public function current(): mixed {
    * current row. It must be a scalar - we will serialize to fulfill the
    * requirement, but using getCurrentKey() is preferable.
    */
-  public function key(): mixed {
+  #[\ReturnTypeWillChange]
+  public function key() {
     return serialize($this->currentKey);
   }
 
@@ -989,7 +992,8 @@ public function currentSource() {
    * This is called at the bottom of the loop implicitly, as well as explicitly
    * from rewind().
    */
-  public function next(): void {
+  #[\ReturnTypeWillChange]
+  public function next() {
     $this->currentRow = $this->result->fetchAssoc();
     $this->currentKey = [];
     if ($this->currentRow) {
@@ -1007,7 +1011,8 @@ public function next(): void {
    * This is called at the top of the loop, returning TRUE to process the loop
    * and FALSE to terminate it.
    */
-  public function valid(): bool {
+  #[\ReturnTypeWillChange]
+  public function valid() {
     return $this->currentRow !== FALSE;
   }
 
diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php
index 90a66e45ed8a..3191c7256d4a 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php
@@ -343,7 +343,8 @@ protected function getIterator() {
   /**
    * {@inheritdoc}
    */
-  public function current(): mixed {
+  #[\ReturnTypeWillChange]
+  public function current() {
     return $this->currentRow;
   }
 
@@ -355,7 +356,8 @@ public function current(): mixed {
    * serialize to fulfill the requirement, but using getCurrentIds() is
    * preferable.
    */
-  public function key(): mixed {
+  #[\ReturnTypeWillChange]
+  public function key() {
     return serialize($this->currentSourceIds);
   }
 
@@ -365,7 +367,8 @@ public function key(): mixed {
    * Implementation of \Iterator::valid() - called at the top of the loop,
    * returning TRUE to process the loop and FALSE to terminate it.
    */
-  public function valid(): bool {
+  #[\ReturnTypeWillChange]
+  public function valid() {
     return isset($this->currentRow);
   }
 
@@ -376,7 +379,8 @@ public function valid(): bool {
    * should implement initializeIterator() to do any class-specific setup for
    * iterating source records.
    */
-  public function rewind(): void {
+  #[\ReturnTypeWillChange]
+  public function rewind() {
     $this->getIterator()->rewind();
     $this->next();
   }
@@ -384,7 +388,8 @@ public function rewind(): void {
   /**
    * {@inheritdoc}
    */
-  public function next(): void {
+  #[\ReturnTypeWillChange]
+  public function next() {
     $this->currentSourceIds = NULL;
     $this->currentRow = NULL;
 
diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
index f6ce4a00b113..773919205fa1 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
@@ -448,7 +448,8 @@ protected function getMockSource() {
       ->onlyMethods(get_class_methods($class))
       ->getMockForAbstractClass();
     $source->expects($this->once())
-      ->method('rewind');
+      ->method('rewind')
+      ->willReturn(TRUE);
     $source->expects($this->any())
       ->method('initializeIterator')
       ->willReturn([]);
diff --git a/core/tests/Drupal/Tests/StreamCapturer.php b/core/tests/Drupal/Tests/StreamCapturer.php
index 2be2ef60f4f0..eb7d54aa9b76 100644
--- a/core/tests/Drupal/Tests/StreamCapturer.php
+++ b/core/tests/Drupal/Tests/StreamCapturer.php
@@ -11,7 +11,8 @@ class StreamCapturer extends \php_user_filter {
 
   public static $cache = '';
 
-  public function filter($in, $out, &$consumed, $closing): int {
+  #[\ReturnTypeWillChange]
+  public function filter($in, $out, &$consumed, $closing) {
     while ($bucket = stream_bucket_make_writeable($in)) {
       self::$cache .= $bucket->data;
       // cSpell:disable-next-line
-- 
GitLab