[php-src] Issue #13944: getAttribute('xmlns') returns NULL when using the new DOM API
| From: | ausi | Date: | Thu, 11 Apr 2024 17:11:07 +0000 |
| Subject: | [php-src] Issue #13944: getAttribute('xmlns') returns NULL when using the new DOM API | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246743@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13944
Author: ausi
### Description
I was rewriting some code to use the new spec compliant DOM API and noticed something odd:
->getAttribute('xmlns') seems to behave differently than the old
implementation.
```php
// New DOM
$doc = \DOM\XMLDocument::createEmpty();
$doc->appendChild($doc->createElementNS('http://www.w3.org/2000/svg', 'svg'));
var_dump($doc->firstChild->getAttribute('xmlns')); // NULL
$doc2 = \DOM\XMLDocument::createFromString($doc->saveXML());
var_dump($doc2->firstChild->getAttribute('xmlns')); // string(26) "http://www.w3.org/2000/svg"
// Old DOM
$doc = new \DOMDocument();
$doc->appendChild($doc->createElementNS('http://www.w3.org/2000/svg', 'svg'));
var_dump($doc->firstChild->getAttribute('xmlns')); // string(26) "http://www.w3.org/2000/svg"
$doc2 = new \DOMDocument();
$doc2->loadXML($doc->saveXML());
var_dump($doc2->firstChild->getAttribute('xmlns')); // string(26) "http://www.w3.org/2000/svg"
```
->getAttribute('xmlns') returns NULL at first, but after
serializing and parsing the document again it returns "http://www.w3.org/2000/svg"`. I’d have
expected that serializing and parsing produces an identical state of the document, but it didn’t.
I was not able to find out what behavior the specification demands here for
->getAttribute('xmlns').
### PHP Version
PHP 8.4.0-dev
### Operating System
macOS 14.4.1 (23E224)