Skip to content

DOMException: Not Found Error introduced in 8.2.6, 8.1.19 #11289

Closed
@fluffycondor

Description

@fluffycondor

Description

Live reproduce: https://3v4l.org/AgHLn

The following code:

<?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->childNodes);
}

throws DOMException: Not Found Error since 8.2.6 and 8.1.19.
Probably related to #11288.

PHP Version

PHP 8.2.6, 8.1.19

Operating System

FreeBSD 12.4, Windows 10 x64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions