xref: /php-src/ext/simplexml/tests/bug12170.phpt (revision 747335f1)
1--TEST--
2Bug GH-12170 (Can't use xpath with comments in SimpleXML)
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$xml = <<<XML
9<?xml version="1.0" encoding="utf-8"?>
10<foo>
11  <bar>text node</bar>
12  <bar><!-- baz --></bar>
13  <bar><!-- foo --></bar>
14</foo>
15XML;
16
17$sxe = simplexml_load_string($xml);
18
19var_dump(
20    $sxe->xpath('//bar')
21);
22
23foreach ($sxe->xpath('//comment()') as $comment) {
24    var_dump($comment->getName());
25    var_dump($comment->asXML());
26}
27
28?>
29--EXPECT--
30array(3) {
31  [0]=>
32  object(SimpleXMLElement)#2 (1) {
33    [0]=>
34    string(9) "text node"
35  }
36  [1]=>
37  object(SimpleXMLElement)#3 (1) {
38    ["comment"]=>
39    object(SimpleXMLElement)#5 (0) {
40    }
41  }
42  [2]=>
43  object(SimpleXMLElement)#4 (1) {
44    ["comment"]=>
45    object(SimpleXMLElement)#5 (0) {
46    }
47  }
48}
49string(7) "comment"
50string(12) "<!-- baz -->"
51string(7) "comment"
52string(12) "<!-- foo -->"
53