array_014.phpt 698 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. SPL: ArrayIterator::seek()
  3. --FILE--
  4. <?php
  5. $it = new ArrayIterator(range(0,10));
  6. var_dump($it->count());
  7. $it->seek(5);
  8. var_dump($it->current());
  9. $it->seek(4);
  10. var_dump($it->current());
  11. try
  12. {
  13. $it->seek(-1);
  14. var_dump($it->current());
  15. }
  16. catch(Exception $e)
  17. {
  18. echo $e->getMessage() . "\n";
  19. }
  20. try
  21. {
  22. $it->seek(12);
  23. var_dump($it->current());
  24. }
  25. catch(Exception $e)
  26. {
  27. echo $e->getMessage() . "\n";
  28. }
  29. $pos = 0;
  30. foreach($it as $v)
  31. {
  32. $it->seek($pos++);
  33. var_dump($v);
  34. }
  35. ?>
  36. ===DONE===
  37. <?php exit(0); ?>
  38. --EXPECTF--
  39. int(11)
  40. int(5)
  41. int(4)
  42. Seek position -1 is out of range
  43. Seek position 12 is out of range
  44. int(0)
  45. int(1)
  46. int(2)
  47. int(3)
  48. int(4)
  49. int(5)
  50. int(6)
  51. int(7)
  52. int(8)
  53. int(9)
  54. int(10)
  55. ===DONE===