]> granicus.if.org Git - php/commitdiff
Don't accept dir handle in Directory methods
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Sep 2020 12:48:31 +0000 (14:48 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Sep 2020 12:50:40 +0000 (14:50 +0200)
This is an artifact of the shared implementation with readdir() etc.
The method versions should not accept an explicit dir handle, as
they work on the dir handle from the object.

ext/standard/dir.c
ext/standard/dir.stub.php
ext/standard/dir_arginfo.h
ext/standard/tests/directory/DirectoryClass_basic_001.phpt

index 98bff12fc2bc3b5d336d0c7ba32f9e427f47a422..c1c264d1f0a8b166ed9da4bf2b5a46198cc54c5b 100644 (file)
@@ -59,30 +59,32 @@ php_dir_globals dir_globals;
 static zend_class_entry *dir_class_entry_ptr;
 
 #define FETCH_DIRP() \
-       ZEND_PARSE_PARAMETERS_START(0, 1) \
-               Z_PARAM_OPTIONAL \
-               Z_PARAM_RESOURCE_OR_NULL(id) \
-       ZEND_PARSE_PARAMETERS_END(); \
-       if (!id) { \
-               myself = getThis(); \
-               if (myself) { \
-                       if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
-                               zend_throw_error(NULL, "Unable to find my handle property"); \
-                               RETURN_THROWS(); \
-                       } \
-                       if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \
+       myself = getThis(); \
+       if (!myself) { \
+               ZEND_PARSE_PARAMETERS_START(0, 1) \
+                       Z_PARAM_OPTIONAL \
+                       Z_PARAM_RESOURCE_OR_NULL(id) \
+               ZEND_PARSE_PARAMETERS_END(); \
+               if (id) { \
+                       if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \
                                RETURN_THROWS(); \
                        } \
                } else { \
                        if (!DIRG(default_dir)) { \
                                zend_type_error("No resource supplied"); \
                                RETURN_THROWS(); \
-                       } else if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \
+                       } \
+                       if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \
                                RETURN_THROWS(); \
                        } \
                } \
        } else { \
-               if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \
+               ZEND_PARSE_PARAMETERS_NONE(); \
+               if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
+                       zend_throw_error(NULL, "Unable to find my handle property"); \
+                       RETURN_THROWS(); \
+               } \
+               if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \
                        RETURN_THROWS(); \
                } \
        }
index fb129acaef21c4ac02e2e67fbdcc625268e15a1b..9904c6bc992d606c392004da39b0ade677ecc1db 100755 (executable)
@@ -5,23 +5,20 @@
 class Directory
 {
     /**
-     * @param resource|null $dir_handle
      * @return void
      * @implementation-alias closedir
      */
-    public function close($dir_handle = null) {}
+    public function close() {}
 
     /**
-     * @param resource|null $dir_handle
      * @return void
      * @implementation-alias rewinddir
      */
-    public function rewind($dir_handle = null) {}
+    public function rewind() {}
 
     /**
-     * @param resource|null $dir_handle
      * @return string|false
      * @implementation-alias readdir
      */
-    public function read($dir_handle = null) {}
+    public function read() {}
 }
index a9f836d53a5d507a782b43ddf9c80512a28d0d76..a2fa03611cab842b3b95f81db2870d7423a39bf9 100644 (file)
@@ -1,8 +1,7 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: d8d8c93a1659e1790b25a65d7e1d0d7430724e9d */
+ * Stub hash: a715bf6a8d5fe69732623cc17f03bd463f369648 */
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Directory_close, 0, 0, 0)
-       ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, dir_handle, "null")
 ZEND_END_ARG_INFO()
 
 #define arginfo_class_Directory_rewind arginfo_class_Directory_close
index 7e3c53b7970e27d0cfbcd22fc982f8593870d7a8..9ccceda920437a0f61e212cb467698f7a572beec 100644 (file)
@@ -41,22 +41,19 @@ Class [ <internal%s> class Directory ] {
   - Methods [3] {
     Method [ <internal:standard> public method close ] {
 
-      - Parameters [1] {
-        Parameter #0 [ <optional> $dir_handle = null ]
+      - Parameters [0] {
       }
     }
 
     Method [ <internal:standard> public method rewind ] {
 
-      - Parameters [1] {
-        Parameter #0 [ <optional> $dir_handle = null ]
+      - Parameters [0] {
       }
     }
 
     Method [ <internal:standard> public method read ] {
 
-      - Parameters [1] {
-        Parameter #0 [ <optional> $dir_handle = null ]
+      - Parameters [0] {
       }
     }
   }