Skip to content

Commit a0f2110

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_directory.c
1 parent ccd9da0 commit a0f2110

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

ext/spl/spl_directory.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
720720
return;
721721
}
722722
if (!len) {
723-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Directory name must not be empty.");
723+
zend_value_error("Directory name must not be empty");
724724
zend_restore_error_handling(&error_handling);
725725
return;
726726
}
@@ -852,7 +852,7 @@ SPL_METHOD(DirectoryIterator, seek)
852852
valid = zend_is_true(&retval);
853853
zval_ptr_dtor(&retval);
854854
if (!valid) {
855-
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Seek position " ZEND_LONG_FMT " is out of range", pos);
855+
zend_value_error("Seek position " ZEND_LONG_FMT " is out of range", pos);
856856
RETURN_THROWS();
857857
}
858858
zend_call_method_with_0_params(Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), &intern->u.dir.func_next, "next", NULL);
@@ -2500,7 +2500,7 @@ SPL_METHOD(SplFileObject, setMaxLineLen)
25002500
}
25012501

25022502
if (max_len < 0) {
2503-
zend_throw_exception_ex(spl_ce_DomainException, 0, "Maximum line length must be greater than or equal zero");
2503+
zend_value_error("Maximum line length must be greater than or equal zero");
25042504
RETURN_THROWS();
25052505
}
25062506

@@ -2965,7 +2965,7 @@ SPL_METHOD(SplFileObject, seek)
29652965
}
29662966

29672967
if (line_pos < 0) {
2968-
zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't seek file %s to negative line " ZEND_LONG_FMT, intern->file_name, line_pos);
2968+
zend_value_error("Can't seek file %s to negative line", intern->file_name);
29692969
RETURN_THROWS();
29702970
}
29712971

ext/spl/tests/DirectoryIterator_empty_constructor.phpt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ Havard Eide <nucleuz@gmail.com>
55
#PHPTestFest2009 Norway 2009-06-09 \o/
66
--FILE--
77
<?php
8-
$it = new DirectoryIterator("");
8+
9+
try {
10+
new DirectoryIterator("");
11+
} catch (\ValueError $ex) {
12+
echo $ex->getMessage() . PHP_EOL;
13+
}
14+
915
?>
10-
--EXPECTF--
11-
Fatal error: Uncaught RuntimeException: Directory name must not be empty. in %s:%d
12-
Stack trace:
13-
#0 %s(%d): DirectoryIterator->__construct('')
14-
#1 {main}
15-
thrown in %s on line %d
16+
--EXPECT--
17+
Directory name must not be empty

ext/spl/tests/SplFileObject_seek_error_001.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ SplFileObject::seek function - test parameters
44
<?php
55
$obj = new SplFileObject(__FILE__);
66
try {
7-
$obj->seek(-1);
8-
} catch (LogicException $e) {
9-
echo($e->getMessage());
7+
$obj->seek(-1);
8+
} catch (\ValueError $e) {
9+
echo($e->getMessage());
1010
}
1111
?>
1212
--EXPECTF--
13-
Can't seek file %s to negative line -1
13+
Can't seek file %s to negative line

ext/spl/tests/bug70561.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ while ($di->valid()) {
1313

1414
try {
1515
$di->seek($cnt+1);
16-
} catch (OutOfBoundsException $ex) {
16+
} catch (\ValueError $ex) {
1717
echo $ex->getMessage() . PHP_EOL;
1818
}
1919
echo "Is valid? " . (int) $di->valid() . PHP_EOL;

ext/spl/tests/dit_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ try {
3434
$p = 0;
3535
$di->seek($o+1);
3636
$p = 1;
37-
} catch (\OutOfBoundsException $ex) {
37+
} catch (\ValueError $ex) {
3838
echo $ex->getMessage() . PHP_EOL;
3939
}
4040

ext/spl/tests/fileobject_setmaxlinelen_error001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ $s = new SplFileObject( __FILE__ );
88
try {
99
$s->setMaxLineLen(-1);
1010
}
11-
catch (DomainException $e) {
12-
echo 'DomainException thrown';
11+
catch (\ValueError $e) {
12+
echo($e->getMessage());
1313
}
1414

1515
?>
1616
--EXPECT--
17-
DomainException thrown
17+
Maximum line length must be greater than or equal zero

0 commit comments

Comments
 (0)