[php-src] Issue #12169: Unable to get comment contents in SimpleXML
| From: | nielsdos | Date: | Sun, 10 Sep 2023 19:14:29 +0000 |
| Subject: | [php-src] Issue #12169: Unable to get comment contents in SimpleXML | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245376@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12169
Author: nielsdos
### Description
Bug report or feature request, I don't know for sure... Could be considered either?
Anyway:
```php
<?php
$sxe = simplexml_load_string(<<<XML
<?xml version="1.0"?>
<container>
<bar>hi</bar>
<!-- comment -->
</container>
XML);
var_dump((string) $sxe->bar);
var_dump((string) $sxe->comment);
```
Gives output:
```
string(2) "hi"
string(0) ""
```
But I expected:
```
string(2) "hi"
string(7) "comment"
```
Looking at the documentation for __toString: https://www.php.net/manual/en/simplexmlelement.tostring.php
> Returns text content that is directly in this element. (...)
Well, the confusing thing is that every XML node is called a SimpleXMLElement in ext/simplexml, even
if they're not XML elements. But that aside, if I read the docs as "Returns text content
that is directly in this node." then I would expect the cast to give me the comment contents,
as that's the text inside of it.