Avoid updates to DOMNodeList for childNodes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 12 Apr 2021 17:21:21 +0000 (19:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 12 Apr 2021 17:21:21 +0000 (19:21 +0200)
wcfsetup/install/files/lib/util/DOMUtil.class.php

index 52c46077272103ec187a9426be17aa7ddc362794..238d5a1f244805d252f071cf5dbec4bee03ff3c4 100644 (file)
@@ -483,8 +483,13 @@ final class DOMUtil {
                                throw new \InvalidArgumentException("Preserving child nodes is only supported for DOMElement.");
                        }
                        
-                       while ($node->hasChildNodes()) {
-                               self::insertBefore($node->childNodes->item(0), $node);
+                       $children = [];
+                       foreach ($node->childNodes as $childNode) {
+                               $children[] = $childNode;
+                       }
+
+                       foreach ($children as $child) {
+                               self::insertBefore($child, $node);
                        }
                }