bug61527.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. Bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
  3. --FILE--
  4. <?php
  5. $ao = new ArrayObject(array());
  6. $ai = $ao->getIterator();
  7. /* testing empty array, should no notice at all */
  8. $ai->next();
  9. var_dump($ai->key());
  10. var_dump($ai->current());
  11. /* testing array changing */
  12. $ao2 = new ArrayObject(array(1 => 1, 2, 3, 4, 5));
  13. $ai2 = $ao2->getIterator();
  14. $ao2->offsetUnset($ai2->key());
  15. $ai2->next();
  16. /* now point to 2 */
  17. $ao2->offsetUnset($ai2->key());
  18. var_dump($ai2->key());
  19. /* now point to 3 */
  20. $ao2->offsetUnset($ai2->key());
  21. var_dump($ai2->current());
  22. $ai2->next();
  23. var_dump($ai2->key());
  24. var_dump($ai2->current());
  25. /* should be at the end and no notice */
  26. $ai2->next();
  27. var_dump($ai2->key());
  28. var_dump($ai2->current());
  29. $ai2->rewind();
  30. $ai2->next();
  31. $ai2->next();
  32. /* should reached the end */
  33. var_dump($ai2->next());
  34. var_dump($ai2->key());
  35. /* testing RecursiveArrayIterator */
  36. $ao3 = new ArrayObject(array(), 0, 'RecursiveArrayIterator');
  37. $ai3 = $ao3->getIterator();
  38. var_dump($ai3->getChildren());
  39. $ao4 = new ArrayObject(array(1, 2), 0, 'RecursiveArrayIterator');
  40. $ai4 = $ao4->getIterator();
  41. $ai4->next();
  42. $ai4->next();
  43. $ai4->next();
  44. var_dump($ai4->hasChildren());
  45. $ai4->rewind();
  46. $ao4->offsetUnset($ai4->key());
  47. var_dump($ai4->hasChildren());
  48. $ao4->offsetUnset($ai4->key());
  49. var_dump($ai4->getChildren());
  50. ?>
  51. ==DONE==
  52. <?php exit(0); ?>
  53. --EXPECT--
  54. NULL
  55. NULL
  56. int(4)
  57. int(5)
  58. NULL
  59. NULL
  60. NULL
  61. NULL
  62. NULL
  63. NULL
  64. NULL
  65. bool(false)
  66. bool(false)
  67. NULL
  68. ==DONE==