[php-src] Issue #11625: PHP 8.2.8: `DOMElement::replaceWith()` doesn't replace node with `DOMDocumentFragment` but just delete node

From: Date: Fri, 07 Jul 2023 18:23:52 +0000
Subject: [php-src] Issue #11625: PHP 8.2.8: `DOMElement::replaceWith()` doesn't replace node with `DOMDocumentFragment` but just delete node
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244911@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11625 Author: fluffycondor ### Description The following code: https://3v4l.org/LqkYK (sorry, no 8.2.8 on 3v4l.org yet) ```php <?php $html = <<<HTML <!DOCTYPE HTML> <html> <body> <div></div> </body> </html> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $divs = iterator_to_array($dom->getElementsByTagName('div')->getIterator()); foreach ($divs as $div) { $fragment = $dom->createDocumentFragment(); $fragment->appendXML('<p>Hi!</p>'); $div->replaceWith($fragment); } echo $dom->saveHTML(); ``` Resulted in this output: ```html <!DOCTYPE HTML> <html> <body> </body> </html> ``` But I expected this output instead: ``` <!DOCTYPE HTML> <html> <body> <p>Hi!</p> </body> </html> ``` It works as expected if I replace the line $div->replaceWith($fragment); with $div->replaceWith(...$fragment->childNodes);. ### PHP Version PHP 8.2.8 ### Operating System _No response_

« previous php.bugs (#244911) next »