Closed
Description
Description
The following code:
<?php
$doc = new DOMDocument;
$doc->loadXML(<<<XML
<?xml version="1.0"?>
<container x="foo">
<test/>
</container>
XML);
try {
$doc->documentElement->firstElementChild->append($doc->documentElement->attributes[0]);
} catch (\DOMException $e) {
echo $e->getMessage(), "\n";
}
echo $doc->saveXML();
Resulted in this output:
Hierarchy Request Error
<?xml version="1.0"?>
<container>
<test/>
</container>
But I expected this output instead:
Hierarchy Request Error
<?xml version="1.0"?>
<container x="foo">
<test/>
</container>
This is because the hierarchy checks are done upon the creation of the fragment, instead of upfront. We should move all the hierarchy and type checking logic upfront.
It looks like this has been around since the introduction of these ParentNode methods.
PHP Version
8.0+
Operating System
No response