[php-src] Issue #22644: [8.4+] Misbehavior between old DOMDocument and new Dom\HTMLDocument in XML handling

[email protected] (stloyd) Wed, 8 Jul 2026 17:25:40 +0000
Newsgroups php.bugs
Message-ID <50qmMIJSUr0KniHcd9OFPdO7b232uOvq8OKhW7BaFkQ@main.internal.php.net>
Issue: https://github.com/php/php-src/issues/22644
Author: stloyd

### Description

The following code:

```php
<?php

$xml = <<<'XML'
<Invoice xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
         xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
         xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
         xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
         xmlns:sh="http://www.unece.org/cefact/nodes/StandardBusinessDocumentHeader">
</Invoice>
XML;

$newDocument = \Dom\HTMLDocument::createFromString($xml, LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR);
$oldDocument = new \DOMDocument();
$oldDocument->loadXML($xml);

var_dump($newDocument->documentElement->namespaceURI, $oldDocument->documentElement->namespaceURI);
```

Resulted in this output:
```
string(28) "http://www.w3.org/1999/xhtml"
string(54) "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
```

But I expected this output instead:
```
string(54) "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
string(54) "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
```


### PHP Version

```plain
PHP 8.4.20 (cli) (built: Apr  8 2026 08:16:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.20, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.20, Copyright (c), by Zend Technologies
```

### Operating System

_No response_