iterator_032.phpt 637 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. SPL: LimitIterator::getPosition()
  3. --FILE--
  4. <?php
  5. $it = new LimitIterator(new ArrayIterator(array(1,2,3,4)), 1, 2);
  6. foreach($it as $k=>$v)
  7. {
  8. echo "$k=>$v\n";
  9. var_dump($it->getPosition());
  10. }
  11. try
  12. {
  13. $it->seek(0);
  14. }
  15. catch(OutOfBoundsException $e)
  16. {
  17. echo $e->getMessage() . "\n";
  18. }
  19. $it->seek(2);
  20. var_dump($it->current());
  21. try
  22. {
  23. $it->seek(3);
  24. }
  25. catch(OutOfBoundsException $e)
  26. {
  27. echo $e->getMessage() . "\n";
  28. }
  29. $it->next();
  30. var_dump($it->valid());
  31. ?>
  32. --EXPECT--
  33. 1=>2
  34. int(1)
  35. 2=>3
  36. int(2)
  37. Cannot seek to 0 which is below the offset 1
  38. int(3)
  39. Cannot seek to 3 which is behind offset 1 plus count 2
  40. bool(false)