Skip to content

Commit c6ec8be

Browse files
committed
Use ValueError instead of exceptions in spl_directory.c
1 parent cd4f1ae commit c6ec8be

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

ext/spl/spl_directory.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,19 +720,19 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
720720
flags |= SPL_FILE_DIR_UNIXPATHS;
721721
}
722722
if (parsed == FAILURE) {
723-
return;
723+
RETURN_THROWS();
724724
}
725725

726-
if (!len) {
727-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Directory name must not be empty.");
728-
return;
726+
if (len == 0) {
727+
zend_argument_value_error(1, "cannot be empty");
728+
RETURN_THROWS();
729729
}
730730

731731
intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
732732
if (intern->_path) {
733733
/* object is already initialized */
734734
zend_throw_error(NULL, "Directory object is already initialized");
735-
return;
735+
RETURN_THROWS();
736736
}
737737
intern->flags = flags;
738738

@@ -2277,7 +2277,7 @@ PHP_METHOD(SplFileObject, setMaxLineLen)
22772277
}
22782278

22792279
if (max_len < 0) {
2280-
zend_throw_exception_ex(spl_ce_DomainException, 0, "Maximum line length must be greater than or equal zero");
2280+
zend_argument_value_error(1, "must be greater than or equal to 0");
22812281
RETURN_THROWS();
22822282
}
22832283

@@ -2724,7 +2724,7 @@ PHP_METHOD(SplFileObject, seek)
27242724
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
27252725

27262726
if (line_pos < 0) {
2727-
zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't seek file %s to negative line " ZEND_LONG_FMT, intern->file_name, line_pos);
2727+
zend_argument_value_error(1, "must be greater than or equal to 0");
27282728
RETURN_THROWS();
27292729
}
27302730

ext/spl/tests/DirectoryIterator_empty_constructor.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Havard Eide <[email protected]>
55
#PHPTestFest2009 Norway 2009-06-09 \o/
66
--FILE--
77
<?php
8-
$it = new DirectoryIterator("");
8+
try {
9+
$it = new DirectoryIterator("");
10+
} catch (\ValueError $e) {
11+
echo $e->getMessage() . \PHP_EOL;
12+
}
913
?>
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
14+
--EXPECT--
15+
DirectoryIterator::__construct(): Argument #1 ($path) cannot be empty

ext/spl/tests/SplFileObject_seek_error_001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ SplFileObject::seek function - test parameters
55
$obj = new SplFileObject(__FILE__);
66
try {
77
$obj->seek(-1);
8-
} catch (LogicException $e) {
8+
} catch (\ValueError $e) {
99
echo($e->getMessage());
1010
}
1111
?>
12-
--EXPECTF--
13-
Can't seek file %s to negative line -1
12+
--EXPECT--
13+
SplFileObject::seek(): Argument #1 ($line_pos) must be greater than or equal to 0

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() . \PHP_EOL;
1313
}
1414

1515
?>
1616
--EXPECT--
17-
DomainException thrown
17+
SplFileObject::setMaxLineLen(): Argument #1 ($max_len) must be greater than or equal to 0

0 commit comments

Comments
 (0)