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.

61 lines
762 B

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