[php-src] Issue #23832: ext/dom: Serialization of empty XML elements differs between new DOM and old
| From: | JKingweb | Date: | Mon, 21 Sep 2026 21:23:35 +0000 |
| Subject: | [php-src] Issue #23832: ext/dom: Serialization of empty XML elements differs between new DOM and old | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252796@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/23832
Author: JKingweb
### Description
The following code:
```php
<?php
$markup = <<<XML_DOC
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="application/xhtml+xml">
<div xmlns="http://www.w3.org/1999/xhtml" xml:base="http://example.com/"/>
</title>
</feed>
XML_DOC;
$new = \Dom\XMLDocument::createFromString($markup);
var_dump($new->saveXml($new->getElementsByTagName("div")->item(0)));
$old = new \DOMDocument;
$old->loadXML($markup);
var_dump($old->saveXml($old->getElementsByTagName("div")->item(0)));
```
Resulted in this output:
```
string(79) "<div xmlns="http://www.w3.org/1999/xhtml" xml:base="http://example.com/"></div>"
string(74) "<div xmlns="http://www.w3.org/1999/xhtml" xml:base="http://example.com/"/>"
```
But I expected this output instead:
```
string(74) "<div xmlns="http://www.w3.org/1999/xhtml" xml:base="http://example.com/"/>"
string(74) "<div xmlns="http://www.w3.org/1999/xhtml" xml:base="http://example.com/"/>"
```
I believe
DOMDocument is acting correctly here and Dom\XMLDocument is in
error, since the LIBXML_NOEMPTYTAG option was not specified.
### PHP Version
```plain
PHP 8.5.10 (cli) (built: Aug 26 2026 07:43:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.10, Copyright (c) Zend Technologies
with Zend OPcache v8.5.10, Copyright (c), by Zend Technologies
```
### Operating System
Arch Linux