From b3d725218d881cb26028af04140f66617df3a06a Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 29 Aug 2019 01:14:17 +0200 Subject: [PATCH] Promote warnings to errors in dir stdlib extension --- ext/standard/dir.c | 16 ++++++++-------- ext/standard/tests/dir/closedir_variation3.phpt | 11 ++++++----- ext/standard/tests/dir/readdir_variation7.phpt | 10 ++++++---- ext/standard/tests/dir/rewinddir_variation3.phpt | 11 +++++++---- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 207b02f5db..31ef72c2b1 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/closedir_variation3.phpt b/ext/standard/tests/dir/closedir_variation3.phpt index 7d7fdcbf0e..7c65f5f877 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 2cd23b8bfc..7950d58823 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 a1ec7f80d4..920e493c07 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 -- 2.50.1