iterator_025.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. SPL: RecursiveIteratorIterator and begin/endIteration()
  3. --FILE--
  4. <?php
  5. class MyRecursiveIteratorIterator extends RecursiveIteratorIterator
  6. {
  7. function beginIteration(): void
  8. {
  9. echo __METHOD__ . "()\n";
  10. }
  11. function endIteration(): void
  12. {
  13. echo __METHOD__ . "()\n";
  14. }
  15. }
  16. $ar = array(1, 2, array(31, 32, array(331)), 4);
  17. $it = new MyRecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator"));
  18. foreach($it as $v) echo "$v\n";
  19. echo "===MORE===\n";
  20. foreach($it as $v) echo "$v\n";
  21. echo "===MORE===\n";
  22. $it->rewind();
  23. foreach($it as $v) echo "$v\n";
  24. var_dump($it->valid());
  25. echo "===MANUAL===\n";
  26. $it->rewind();
  27. while($it->valid())
  28. {
  29. echo $it->current() . "\n";
  30. $it->next();
  31. break;
  32. }
  33. $it->rewind();
  34. while($it->valid())
  35. {
  36. echo $it->current() . "\n";
  37. $it->next();
  38. }
  39. ?>
  40. --EXPECT--
  41. MyRecursiveIteratorIterator::beginIteration()
  42. 1
  43. 2
  44. 31
  45. 32
  46. 331
  47. 4
  48. MyRecursiveIteratorIterator::endIteration()
  49. ===MORE===
  50. MyRecursiveIteratorIterator::beginIteration()
  51. 1
  52. 2
  53. 31
  54. 32
  55. 331
  56. 4
  57. MyRecursiveIteratorIterator::endIteration()
  58. ===MORE===
  59. MyRecursiveIteratorIterator::beginIteration()
  60. 1
  61. 2
  62. 31
  63. 32
  64. 331
  65. 4
  66. MyRecursiveIteratorIterator::endIteration()
  67. bool(false)
  68. ===MANUAL===
  69. MyRecursiveIteratorIterator::beginIteration()
  70. 1
  71. 1
  72. 2
  73. 31
  74. 32
  75. 331
  76. 4
  77. MyRecursiveIteratorIterator::endIteration()