diff --git a/ext/standard/dir.c b/ext/standard/dir.c index f54fe69e25196..82b387534e6c1 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -266,8 +266,8 @@ PHP_FUNCTION(closedir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle); - RETURN_FALSE; + zend_type_error("%d is not a valid Directory resource", dirp->res->handle); + return; } res = dirp->res; @@ -382,8 +382,8 @@ PHP_FUNCTION(rewinddir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle); - RETURN_FALSE; + zend_type_error("%d is not a valid Directory resource", dirp->res->handle); + return; } php_stream_rewinddir(dirp); @@ -401,8 +401,8 @@ PHP_NAMED_FUNCTION(php_if_readdir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle); - RETURN_FALSE; + zend_type_error("%d is not a valid Directory resource", dirp->res->handle); + return; } if (php_stream_readdir(dirp, &entry)) { @@ -566,8 +566,8 @@ PHP_FUNCTION(scandir) ZEND_PARSE_PARAMETERS_END(); if (dirn_len < 1) { - php_error_docref(NULL, E_WARNING, "Directory name cannot be empty"); - RETURN_FALSE; + zend_throw_error(NULL, "Directory name cannot be empty"); + return; } if (zcontext) { diff --git a/ext/standard/tests/dir/bug41693.phpt b/ext/standard/tests/dir/bug41693.phpt new file mode 100644 index 0000000000000..c42ca2faea702 --- /dev/null +++ b/ext/standard/tests/dir/bug41693.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #41693 (scandir() allows empty directory names) +--FILE-- +getMessage() . "\n"; +} + +?> +--EXPECT-- +Directory name cannot be empty diff --git a/ext/standard/tests/dir/closedir_variation3.phpt b/ext/standard/tests/dir/closedir_variation3.phpt index 7d7fdcbf0e587..7c65f5f877789 100644 --- a/ext/standard/tests/dir/closedir_variation3.phpt +++ b/ext/standard/tests/dir/closedir_variation3.phpt @@ -18,8 +18,11 @@ echo "\n-- Open a file using fopen() --\n"; var_dump($fp = fopen(__FILE__, 'r')); echo "\n-- Try to close the file pointer using closedir() --\n"; -var_dump(closedir($fp)); - +try { + var_dump(closedir($fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Check file pointer: --\n"; var_dump($fp); @@ -35,9 +38,7 @@ if(is_resource($fp)) { resource(%d) of type (stream) -- Try to close the file pointer using closedir() -- - -Warning: closedir(): %d is not a valid Directory resource in %s on line %d -bool(false) +%d is not a valid Directory resource -- Check file pointer: -- resource(%d) of type (stream) diff --git a/ext/standard/tests/dir/readdir_variation7.phpt b/ext/standard/tests/dir/readdir_variation7.phpt index 2cd23b8bfceab..7950d58823312 100644 --- a/ext/standard/tests/dir/readdir_variation7.phpt +++ b/ext/standard/tests/dir/readdir_variation7.phpt @@ -15,14 +15,16 @@ echo "*** Testing readdir() : usage variations ***\n"; // get a resource variable var_dump($fp = fopen(__FILE__, "r")); -var_dump( readdir($fp) ); +try { + var_dump( readdir($fp) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== --EXPECTF-- *** Testing readdir() : usage variations *** resource(%d) of type (stream) - -Warning: readdir(): %d is not a valid Directory resource in %s on line %d -bool(false) +%d is not a valid Directory resource ===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation3.phpt b/ext/standard/tests/dir/rewinddir_variation3.phpt index a1ec7f80d42e8..920e493c07bef 100644 --- a/ext/standard/tests/dir/rewinddir_variation3.phpt +++ b/ext/standard/tests/dir/rewinddir_variation3.phpt @@ -18,7 +18,12 @@ echo "\n-- Open a file using fopen --\n"; var_dump($fp = fopen(__FILE__, 'r')); $result1 = fread($fp, 5); -var_dump(rewinddir($fp)); + +try { + var_dump(rewinddir($fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} $result2 = fread($fp, 5); echo "\n-- Check if rewinddir() has repositioned the file pointer --\n"; @@ -34,9 +39,7 @@ if ($result1 === $result2) { -- Open a file using fopen -- resource(%d) of type (stream) - -Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d -bool(false) +%d is not a valid Directory resource -- Check if rewinddir() has repositioned the file pointer -- rewinddir() does not work on file pointers diff --git a/ext/standard/tests/file/bug41693.phpt b/ext/standard/tests/file/bug41693.phpt deleted file mode 100644 index ea074fa4fdddb..0000000000000 --- a/ext/standard/tests/file/bug41693.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Bug #41693 (scandir() allows empty directory names) ---FILE-- - ---EXPECTF-- -Warning: scandir(): Directory name cannot be empty in %s on line %d -bool(false) -Done