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

Can't use xpath with comments in SimpleXML #12170

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

Can't use xpath with comments in SimpleXML #12170

nielsdos opened this issue Sep 10, 2023 · 0 comments

Comments

@nielsdos
Copy link
Member

Description

The following code:

<?php
$sxe = simplexml_load_string(<<<XML
<?xml version="1.0"?>
<container>
    <!-- comment -->
</container>
XML);

var_dump($sxe->xpath("//comment()"));

Resulted in this output:

array(0) {
}

But I expected this output instead:

array(1) {
[0] => the comment node
}

However, you can see the comment node with var_dump($sxe):

object(SimpleXMLElement)#1 (1) {
  ["comment"]=>
  object(SimpleXMLElement)#2 (0) {
  }
}

So SimpleXML can handle it, kinda.

PHP Version

PHP 8.1+

Operating System

Linux

nielsdos added a commit to nielsdos/php-src that referenced this issue Sep 11, 2023
@nielsdos nielsdos linked a pull request Sep 11, 2023 that will close this issue
nielsdos added a commit that referenced this issue Sep 14, 2023
* PHP-8.1:
  Fix GH-12170: Can't use xpath with comments in SimpleXML
nielsdos added a commit that referenced this issue Sep 14, 2023
* PHP-8.2:
  Fix GH-12170: Can't use xpath with comments in SimpleXML
nielsdos added a commit that referenced this issue Sep 14, 2023
* PHP-8.3:
  Fix GH-12170: Can't use xpath with comments 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