Skip to content

Error: Couldn't fetch DOMElement introduced in 8.2.6, 8.1.19 #11288

@fluffycondor

Description

@fluffycondor

Description

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

The following code:

<?php
$html = <<<HTML
<!DOCTYPE HTML>
<html>
<span class="unwrap_me"><i><span class="foo">Lorem</span></i><span class="foo">ipsum</span></span>
</html>
HTML;

$dom = new DOMDocument();
$dom->loadHTML($html);

$spans = iterator_to_array($dom->getElementsByTagName('span')->getIterator());
foreach ($spans as $span) {
    if ('unwrap_me' === $span->getAttribute('class')) {
        $fragment = $dom->createDocumentFragment();
        $fragment->append(...$span->childNodes);
        $span->parentNode?->replaceChild($fragment, $span);
    }
}

worked successfully as for 8.2.5, 8.1.18 and earlier.
But as for 8.2.6 and 8.1.19 it throws Error: Couldn't fetch DOMElement because one of DOMElement's state is corrupted:

object(DOMElement)#142 (1) {
  ["schemaTypeInfo"]=>
  NULL
}
DOMElement Object
(
    [schemaTypeInfo] =>
)

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions