iterator_025.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --TEST--
  2. SPL: RecursiveIteratorIterator and begin/endIteration()
  3. --FILE--
  4. <?php
  5. class MyRecursiveIteratorIterator extends RecursiveIteratorIterator
  6. {
  7. function beginIteration()
  8. {
  9. echo __METHOD__ . "()\n";
  10. }
  11. function endIteration()
  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. ===DONE===
  41. <?php exit(0); ?>
  42. --EXPECT--
  43. MyRecursiveIteratorIterator::beginIteration()
  44. 1
  45. 2
  46. 31
  47. 32
  48. 331
  49. 4
  50. MyRecursiveIteratorIterator::endIteration()
  51. ===MORE===
  52. MyRecursiveIteratorIterator::beginIteration()
  53. 1
  54. 2
  55. 31
  56. 32
  57. 331
  58. 4
  59. MyRecursiveIteratorIterator::endIteration()
  60. ===MORE===
  61. MyRecursiveIteratorIterator::beginIteration()
  62. 1
  63. 2
  64. 31
  65. 32
  66. 331
  67. 4
  68. MyRecursiveIteratorIterator::endIteration()
  69. bool(false)
  70. ===MANUAL===
  71. MyRecursiveIteratorIterator::beginIteration()
  72. 1
  73. 1
  74. 2
  75. 31
  76. 32
  77. 331
  78. 4
  79. MyRecursiveIteratorIterator::endIteration()
  80. ===DONE===