]> granicus.if.org Git - php/commitdiff
Promote warnings to errors in dir stdlib extension
authorGeorge Peter Banyard <girgias@php.net>
Wed, 28 Aug 2019 23:14:17 +0000 (01:14 +0200)
committerJoe Watkins <krakjoe@php.net>
Fri, 30 Aug 2019 07:50:04 +0000 (09:50 +0200)
ext/standard/dir.c
ext/standard/tests/dir/closedir_variation3.phpt
ext/standard/tests/dir/readdir_variation7.phpt
ext/standard/tests/dir/rewinddir_variation3.phpt

index 207b02f5dbb0e4f268ab80eae8b711de02be5386..31ef72c2b19ea8f52409bf1072cbe40ea55fb9c2 100644 (file)
@@ -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) {
index 7d7fdcbf0e5870a871b356c9a6c82f27a43984c0..7c65f5f877789f8ead1b5817998b3400c79d7baa 100644 (file)
@@ -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)
index 2cd23b8bfceab74db2682c58ecf1b47429003450..7950d5882331227512aa547a8e9264e2e4614dee 100644 (file)
@@ -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===
index a1ec7f80d42e8c1997482aa8a3e3c555a3f10355..920e493c07bef29610acc359c7dda02de9eb650b 100644 (file)
@@ -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