bug42259.phpt 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Bug #42259 (SimpleXMLIterator loses ancestry)
  3. --EXTENSIONS--
  4. simplexml
  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>
  23. EOF;
  24. $sxe = new SimpleXMLIterator($xml);
  25. $rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY);
  26. foreach ($rit as $child) {
  27. $path = '';
  28. $ancestry = $child->xpath('ancestor-or-self::*');
  29. foreach ($ancestry as $ancestor) {
  30. $path .= $ancestor->getName() . '/';
  31. }
  32. $path = substr($path, 0, strlen($path) - 1);
  33. echo count($ancestry) . ' steps: ' . $path . PHP_EOL;
  34. }
  35. ?>
  36. --EXPECT--
  37. 3 steps: xml/fieldset1/field1
  38. 3 steps: xml/fieldset1/field2
  39. 4 steps: xml/fieldset2/options/option1
  40. 4 steps: xml/fieldset2/options/option2
  41. 4 steps: xml/fieldset2/options/option3
  42. 3 steps: xml/fieldset2/field1
  43. 3 steps: xml/fieldset2/field2