Closed
Description
Description
The following code:
<?php
$d = new \DOMDocument();
$d->appendChild($d->createElement('root'));
$d->createAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns');
Resulted in this output:
PHP Fatal error: Uncaught DOMException: Namespace Error
But I expected this output instead:
N/A
The first step of the DOM specification for createElementNS is:
- Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
The validate and extract section has the following steps:
- If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException.
- If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException.
- If either qualifiedName or prefix is "xmlns" and namespace is not the XMLNS namespace, then throw a "NamespaceError" DOMException.
- If namespace is the XMLNS namespace and neither qualifiedName nor prefix is "xmlns", then throw a "NamespaceError" DOMException.
The namespace is the XMLNS namespace, and the qualifiedName is "xmlns", so it shouldn't be throwing a DOMException. PHP 8.2.x doesn't throw the DOMException. My system has libxml 2.12.1.
PHP Version
PHP 8.3.0
Operating System
macOS 13.4.1