mirror of
https://github.com/php/php-src.git
synced 2024-09-29 05:46:06 +00:00
368d3ff0d9
------------------------------------------------------------------------------- DirectoryIterator implements SeekableIterator, which "should throw an OutOfBoundsException if the position is not seekable". As is, seek just returns and one must call valid(). This approach is different than most (all?) other SeekableIterator implementations and leads to developer confusion. See the bug report for a specific example.
24 lines
438 B
PHP
24 lines
438 B
PHP
--TEST--
|
|
Bug #70561 (DirectoryIterator::seek should throw OutOfBoundsException)
|
|
--FILE--
|
|
<?php
|
|
$di = new DirectoryIterator(__DIR__ . '/..');
|
|
|
|
$cnt = 0;
|
|
$di->rewind();
|
|
while ($di->valid()) {
|
|
$cnt++;
|
|
$di->next();
|
|
}
|
|
|
|
try {
|
|
$di->seek($cnt+1);
|
|
} catch (OutOfBoundsException $ex) {
|
|
echo $ex->getMessage() . PHP_EOL;
|
|
}
|
|
echo "Is valid? " . (int) $di->valid() . PHP_EOL;
|
|
?>
|
|
--EXPECTF--
|
|
Seek position %d is out of range
|
|
Is valid? 0
|