Skip to content

Creating an xmlns attribute results in a DOMException #12870

Closed
@dustinwilson

Description

@dustinwilson

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:

  1. 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:

  1. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException.
  2. If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException.
  3. If either qualifiedName or prefix is "xmlns" and namespace is not the XMLNS namespace, then throw a "NamespaceError" DOMException.
  4. 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions