iterator_042.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. --TEST--
  2. SPL: AppendIterator and its ArrayIterator
  3. --FILE--
  4. <?php
  5. function test_error_handler($errno, $msg, $filename, $linenum, $vars)
  6. {
  7. echo "Error $msg in $filename on line $linenum\n";
  8. return true;
  9. }
  10. set_error_handler('test_error_handler');
  11. $it = new AppendIterator;
  12. $it->append(array());
  13. $it->append(new ArrayIterator(array(1)));
  14. $it->append(new ArrayIterator(array(21, 22)));
  15. var_dump($it->getArrayIterator());
  16. $it->append(new ArrayIterator(array(31, 32, 33)));
  17. var_dump($it->getArrayIterator());
  18. $idx = 0;
  19. foreach($it as $k => $v)
  20. {
  21. echo '===' . $idx++ . "===\n";
  22. var_dump($it->getIteratorIndex());
  23. var_dump($k);
  24. var_dump($v);
  25. }
  26. ?>
  27. ===DONE===
  28. <?php exit(0); ?>
  29. --EXPECTF--
  30. Error Argument 1 passed to AppendIterator::append() must implement interface Iterator, array given in %siterator_042.php on line %d
  31. object(ArrayIterator)#%d (1) {
  32. %s"storage"%s"ArrayIterator":private]=>
  33. array(2) {
  34. [0]=>
  35. object(ArrayIterator)#%d (1) {
  36. %s"storage"%s"ArrayIterator":private]=>
  37. array(1) {
  38. [0]=>
  39. int(1)
  40. }
  41. }
  42. [1]=>
  43. object(ArrayIterator)#%d (1) {
  44. %s"storage"%s"ArrayIterator":private]=>
  45. array(2) {
  46. [0]=>
  47. int(21)
  48. [1]=>
  49. int(22)
  50. }
  51. }
  52. }
  53. }
  54. object(ArrayIterator)#%d (1) {
  55. %s"storage"%s"ArrayIterator":private]=>
  56. array(3) {
  57. [0]=>
  58. object(ArrayIterator)#%d (1) {
  59. %s"storage"%s"ArrayIterator":private]=>
  60. array(1) {
  61. [0]=>
  62. int(1)
  63. }
  64. }
  65. [1]=>
  66. object(ArrayIterator)#%d (1) {
  67. %s"storage"%s"ArrayIterator":private]=>
  68. array(2) {
  69. [0]=>
  70. int(21)
  71. [1]=>
  72. int(22)
  73. }
  74. }
  75. [2]=>
  76. object(ArrayIterator)#5 (1) {
  77. %s"storage"%s"ArrayIterator":private]=>
  78. array(3) {
  79. [0]=>
  80. int(31)
  81. [1]=>
  82. int(32)
  83. [2]=>
  84. int(33)
  85. }
  86. }
  87. }
  88. }
  89. ===0===
  90. int(0)
  91. int(0)
  92. int(1)
  93. ===1===
  94. int(1)
  95. int(0)
  96. int(21)
  97. ===2===
  98. int(1)
  99. int(1)
  100. int(22)
  101. ===3===
  102. int(2)
  103. int(0)
  104. int(31)
  105. ===4===
  106. int(2)
  107. int(1)
  108. int(32)
  109. ===5===
  110. int(2)
  111. int(2)
  112. int(33)
  113. ===DONE===