xref: /php-src/ext/simplexml/tests/bug42259.phpt (revision 7f2f0c00)
1--TEST--
2Bug #42259 (SimpleXMLIterator loses ancestry)
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7$xml =<<<EOF
8<xml>
9  <fieldset1>
10    <field1/>
11    <field2/>
12  </fieldset1>
13  <fieldset2>
14    <options>
15      <option1/>
16      <option2/>
17      <option3/>
18    </options>
19    <field1/>
20    <field2/>
21  </fieldset2>
22</xml>
23EOF;
24
25$sxe = new SimpleXMLIterator($xml);
26$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY);
27foreach ($rit as $child) {
28  $path = '';
29  $ancestry = $child->xpath('ancestor-or-self::*');
30  foreach ($ancestry as $ancestor) {
31    $path .= $ancestor->getName() . '/';
32  }
33  $path = substr($path, 0, strlen($path) - 1);
34  echo count($ancestry) . ' steps: ' . $path . PHP_EOL;
35}
36?>
37--EXPECT--
383 steps: xml/fieldset1/field1
393 steps: xml/fieldset1/field2
404 steps: xml/fieldset2/options/option1
414 steps: xml/fieldset2/options/option2
424 steps: xml/fieldset2/options/option3
433 steps: xml/fieldset2/field1
443 steps: xml/fieldset2/field2
45