You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
698 B

  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===