Commit 0b70abc40fe for php.net

commit 0b70abc40fe7cddf8d85a30685ed9d70c51cf2bc
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date:   Mon Mar 30 21:26:29 2026 +0200

    gen_stub: Implement deep cloning using `array_map()` (#21555)

    This is for forward compatibility when the deep-cloned arrays will become
    `readonly`. Reassigning each item individually is not allowed then.

diff --git a/build/gen_stub.php b/build/gen_stub.php
index 9aac6b23e78..7808929c86c 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -54,6 +54,24 @@ function array_any(array $array, callable $callback): bool {
     }
 }

+if (function_exists('clone')) {
+    // Replace (\clone)(...) with \clone(...) once the minimally
+    // supported PHP version is 8.5.
+    define('clone', \clone(...));
+} else {
+    define(
+        'clone',
+        /**
+         * @template T
+         * @param T $o
+         * @return T
+         */
+        function (object $o): object {
+            return clone $o;
+        }
+    );
+}
+
 /**
  * @return FileInfo[]
  */
@@ -2184,9 +2202,7 @@ public function toArgInfoCode(?int $minPHPCompatibility): string {

     public function __clone()
     {
-        foreach ($this->args as $key => $argInfo) {
-            $this->args[$key] = clone $argInfo;
-        }
+        $this->args = array_map((\clone)(...), $this->args);
         $this->return = clone $this->return;
     }
 }
@@ -4154,17 +4170,9 @@ private function createIncludeElement(DOMDocument $doc, string $query, int $inde

     public function __clone()
     {
-        foreach ($this->constInfos as $key => $constInfo) {
-            $this->constInfos[$key] = clone $constInfo;
-        }
-
-        foreach ($this->propertyInfos as $key => $propertyInfo) {
-            $this->propertyInfos[$key] = clone $propertyInfo;
-        }
-
-        foreach ($this->funcInfos as $key => $funcInfo) {
-            $this->funcInfos[$key] = clone $funcInfo;
-        }
+        $this->constInfos = array_map((\clone)(...), $this->constInfos);
+        $this->propertyInfos = array_map((\clone)(...), $this->propertyInfos);
+        $this->funcInfos = array_map((\clone)(...), $this->funcInfos);
     }

     /**
@@ -4275,17 +4283,9 @@ public function getAllConstInfos(): array {

     public function __clone()
     {
-        foreach ($this->constInfos as $key => $constInfo) {
-            $this->constInfos[$key] = clone $constInfo;
-        }
-
-        foreach ($this->funcInfos as $key => $funcInfo) {
-            $this->funcInfos[$key] = clone $funcInfo;
-        }
-
-        foreach ($this->classInfos as $key => $classInfo) {
-            $this->classInfos[$key] = clone $classInfo;
-        }
+        $this->constInfos = array_map((\clone)(...), $this->constInfos);
+        $this->funcInfos = array_map((\clone)(...), $this->funcInfos);
+        $this->classInfos = array_map((\clone)(...), $this->classInfos);
     }

     private function getMinimumPhpVersionIdCompatibility(): ?int {