Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get comment contents in SimpleXML #12169

Closed
nielsdos opened this issue Sep 10, 2023 · 0 comments
Closed

Unable to get comment contents in SimpleXML #12169

nielsdos opened this issue Sep 10, 2023 · 0 comments

Comments

@nielsdos
Copy link
Member

Description

Bug report or feature request, I don't know for sure... Could be considered either?

Anyway:

<?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.

nielsdos added a commit to nielsdos/php-src that referenced this issue Sep 23, 2023
nielsdos added a commit that referenced this issue Sep 25, 2023
nielsdos added a commit that referenced this issue Sep 25, 2023
* PHP-8.1:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
nielsdos added a commit that referenced this issue Sep 25, 2023
* PHP-8.2:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
nielsdos added a commit that referenced this issue Sep 25, 2023
* PHP-8.3:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant