sxe_004.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. --TEST--
  2. SPL: SimpleXMLIterator and overridden iterator methods()
  3. --EXTENSIONS--
  4. simplexml
  5. libxml
  6. --FILE--
  7. <?php
  8. $xml =<<<EOF
  9. <?xml version='1.0'?>
  10. <!DOCTYPE sxe SYSTEM "notfound.dtd">
  11. <sxe id="elem1">
  12. Plain text.
  13. <elem1 attr1='first'>
  14. Bla bla 1.
  15. <!-- comment -->
  16. <elem2>
  17. Here we have some text data.
  18. <elem3>
  19. And here some more.
  20. <elem4>
  21. Wow once again.
  22. </elem4>
  23. </elem3>
  24. </elem2>
  25. </elem1>
  26. <elem11 attr2='second'>
  27. Bla bla 2.
  28. <elem111>
  29. Foo Bar
  30. </elem111>
  31. </elem11>
  32. </sxe>
  33. EOF;
  34. class SXETest extends SimpleXMLIterator
  35. {
  36. function rewind(): void
  37. {
  38. echo __METHOD__ . "\n";
  39. parent::rewind();
  40. }
  41. function valid(): bool
  42. {
  43. echo __METHOD__ . "\n";
  44. return parent::valid();
  45. }
  46. function current(): SimpleXMLElement
  47. {
  48. echo __METHOD__ . "\n";
  49. return parent::current();
  50. }
  51. function key(): string
  52. {
  53. echo __METHOD__ . "\n";
  54. return parent::key();
  55. }
  56. function next(): void
  57. {
  58. echo __METHOD__ . "\n";
  59. parent::next();
  60. }
  61. function hasChildren(): bool
  62. {
  63. echo __METHOD__ . "\n";
  64. return parent::hasChildren();
  65. }
  66. function getChildren(): ?SimpleXMLIterator
  67. {
  68. echo __METHOD__ . "\n";
  69. return parent::getChildren();
  70. }
  71. }
  72. $sxe = new SXETest($xml);
  73. $rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST);
  74. foreach($rit as $data) {
  75. var_dump(get_class($data));
  76. var_dump(trim($data));
  77. }
  78. ?>
  79. --EXPECT--
  80. SXETest::rewind
  81. SXETest::valid
  82. SXETest::hasChildren
  83. SXETest::valid
  84. SXETest::current
  85. string(7) "SXETest"
  86. string(10) "Bla bla 1."
  87. SXETest::getChildren
  88. SXETest::rewind
  89. SXETest::valid
  90. SXETest::hasChildren
  91. SXETest::valid
  92. SXETest::current
  93. string(7) "SXETest"
  94. string(28) "Here we have some text data."
  95. SXETest::getChildren
  96. SXETest::rewind
  97. SXETest::valid
  98. SXETest::hasChildren
  99. SXETest::valid
  100. SXETest::current
  101. string(7) "SXETest"
  102. string(19) "And here some more."
  103. SXETest::getChildren
  104. SXETest::rewind
  105. SXETest::valid
  106. SXETest::hasChildren
  107. SXETest::valid
  108. SXETest::current
  109. string(7) "SXETest"
  110. string(15) "Wow once again."
  111. SXETest::next
  112. SXETest::valid
  113. SXETest::next
  114. SXETest::valid
  115. SXETest::next
  116. SXETest::valid
  117. SXETest::next
  118. SXETest::valid
  119. SXETest::hasChildren
  120. SXETest::valid
  121. SXETest::current
  122. string(7) "SXETest"
  123. string(10) "Bla bla 2."
  124. SXETest::getChildren
  125. SXETest::rewind
  126. SXETest::valid
  127. SXETest::hasChildren
  128. SXETest::valid
  129. SXETest::current
  130. string(7) "SXETest"
  131. string(7) "Foo Bar"
  132. SXETest::next
  133. SXETest::valid
  134. SXETest::next
  135. SXETest::valid
  136. SXETest::valid