Replace use of a PHP 8+ feature
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 Jul 2022 10:20:11 +0000 (12:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 Jul 2022 10:20:11 +0000 (12:20 +0200)
`DOMElement::$childElementCount` is supported in PHP 8.0+ only, for PHP 7 we need to manually check for child elements.

See https://www.woltlab.com/community/thread/296485-zitat-von-user-nochmal-zitieren/

wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index 9385bea52d923a4d402fdd82436eaf5cd3733d15..c672bebdbde83c85daa2cf02531c630fdcd1bbb5 100644 (file)
@@ -319,7 +319,18 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor
         if ($depth === 0 && $isFullQuote && \count($quotes) > 0) {
             /** @var \DOMElement $body */
             $body = $this->getDocument()->getElementsByTagName('body')[0];
-            if ($body->childElementCount === 0) {
+
+            // TODO: This can be simplified in PHP 8.0+ by checking against `$body->childElementCount`.
+            $hasChildren = false;
+            /** @var \DOMNode $node */
+            foreach ($body->childNodes as $node) {
+                if ($node->nodeType === \XML_ELEMENT_NODE) {
+                    $hasChildren = true;
+                    break;
+                }
+            }
+
+            if (!$hasChildren) {
                 $p = $body->ownerDocument->createElement('p');
                 $p->textContent = "[\u{2026}]";
                 $body->appendChild($p);