Merge branch 'PHP-5.6' into PHP-7.0

* PHP-5.6:
  Fix bug #64172
  Bug #70561: Fix DirectoryIterator to throw OutOfBoundsException

Conflicts:
	ext/pdo/pdo_dbh.c
This commit is contained in:
Stanislav Malyshev 2015-10-18 17:20:00 -07:00
commit 26e5429f72
3 changed files with 32 additions and 6 deletions

View File

@ -834,7 +834,8 @@ SPL_METHOD(DirectoryIterator, seek)
zval_ptr_dtor(&retval);
}
if (!valid) {
break;
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", pos);
return;
}
zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_next, "next", NULL);
}

View File

@ -0,0 +1,23 @@
--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

View File

@ -30,11 +30,12 @@ while ($di->valid()) {
echo "Without seek we get $o\n";
$p = 0;
$di->seek($o+1);
while ($di->valid()) {
$p++;
$di->next();
try {
$p = 0;
$di->seek($o+1);
$p = 1;
} catch (\OutOfBoundsException $ex) {
echo $ex->getMessage() . PHP_EOL;
}
var_dump($n !== $m, $m === $o, $p === 0);
@ -44,6 +45,7 @@ var_dump($n !== $m, $m === $o, $p === 0);
With seek(2) we get %d
With seek(0) we get %d
Without seek we get %d
Seek position %d is out of range
bool(true)
bool(true)
bool(true)