Skip to content

Namespace reuse in createElementNS() generates wrong output #11500

Closed
@ausi

Description

@ausi

Description

The following code:

<?php
$dom = new \DOMDocument();
$root = $dom->createElementNS('http://example.com', 'root');
$dom->appendChild($root);

$a1 = $dom->createElementNS('http://example.com', 'a');
$a1->appendChild($dom->createElementNS('http://example.com', 'b'));
$root->appendChild($a1);

$a2 = $dom->createElementNS('http://example.com', 'a');
$a2->appendChild($dom->createElementNS('http://example.com', 'b'));
$root->appendChild($a2);

echo $dom->saveXML();

Resulted in this output:

<?xml version="1.0"?>
<root xmlns="http://example.com"><a><b/></a><a><b xmlns="http://example.com"/></a></root>

But I expected this output instead:

<?xml version="1.0"?>
<root xmlns="http://example.com"><a><b/></a><a><b/></a></root>

Only the nightly build from the master branch seems to be affected.
With the stable releases this bug does not occur, see https://3v4l.org/hAXOS

Related: #11428 (comment)

PHP Version

8.3.0-dev fe6263e
ext-dom: 20031129
lib-libxml: 2.9.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions