[php-src] Issue #12168: Mixing processing instructions and element nodes gives inconsistent results in SimpleXML
| From: | nielsdos | Date: | Sun, 10 Sep 2023 17:09:18 +0000 |
| Subject: | [php-src] Issue #12168: Mixing processing instructions and element nodes gives inconsistent results in SimpleXML | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245375@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12168
Author: nielsdos
### Description
The following code:
```php
<?php
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<container>
<x/><?hello world?>
</container>
XML;
$sxe = simplexml_load_string($xml);
var_dump($sxe->children());
// x and hello swapped
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<container>
<?hello world?><x/>
</container>
XML;
$sxe = simplexml_load_string($xml);
var_dump($sxe->children());
```
Resulted in this output:
```
object(SimpleXMLElement)#2 (2) {
["x"]=>
object(SimpleXMLElement)#4 (0) {
}
["hello"]=>
object(SimpleXMLElement)#5 (0) {
}
}
object(SimpleXMLElement)#1 (1) {
["x"]=>
object(SimpleXMLElement)#5 (0) {
}
}
```
But I expected this output instead:
```
object(SimpleXMLElement)#2 (2) {
["x"]=>
object(SimpleXMLElement)#4 (0) {
}
["hello"]=>
object(SimpleXMLElement)#5 (0) {
}
}
object(SimpleXMLElement)#1 (1) {
["hello"]=>
object(SimpleXMLElement)#%d (0) {
}
["x"]=>
object(SimpleXMLElement)#%d (0) {
}
}
```
### PHP Version
PHP 8.1+
### Operating System
Linux