Skip to content

Commit 59aa21c

Browse files
committed
Don't accept dir handle in Directory methods
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.
1 parent 739eb43 commit 59aa21c

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

ext/standard/dir.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,32 @@ php_dir_globals dir_globals;
5959
static zend_class_entry *dir_class_entry_ptr;
6060

6161
#define FETCH_DIRP() \
62-
ZEND_PARSE_PARAMETERS_START(0, 1) \
63-
Z_PARAM_OPTIONAL \
64-
Z_PARAM_RESOURCE_OR_NULL(id) \
65-
ZEND_PARSE_PARAMETERS_END(); \
66-
if (!id) { \
67-
myself = getThis(); \
68-
if (myself) { \
69-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
70-
zend_throw_error(NULL, "Unable to find my handle property"); \
71-
RETURN_THROWS(); \
72-
} \
73-
if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \
62+
myself = getThis(); \
63+
if (!myself) { \
64+
ZEND_PARSE_PARAMETERS_START(0, 1) \
65+
Z_PARAM_OPTIONAL \
66+
Z_PARAM_RESOURCE_OR_NULL(id) \
67+
ZEND_PARSE_PARAMETERS_END(); \
68+
if (id) { \
69+
if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \
7470
RETURN_THROWS(); \
7571
} \
7672
} else { \
7773
if (!DIRG(default_dir)) { \
7874
zend_type_error("No resource supplied"); \
7975
RETURN_THROWS(); \
80-
} else if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \
76+
} \
77+
if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \
8178
RETURN_THROWS(); \
8279
} \
8380
} \
8481
} else { \
85-
if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \
82+
ZEND_PARSE_PARAMETERS_NONE(); \
83+
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
84+
zend_throw_error(NULL, "Unable to find my handle property"); \
85+
RETURN_THROWS(); \
86+
} \
87+
if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \
8688
RETURN_THROWS(); \
8789
} \
8890
}

ext/standard/dir.stub.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@
55
class Directory
66
{
77
/**
8-
* @param resource|null $dir_handle
98
* @return void
109
* @implementation-alias closedir
1110
*/
12-
public function close($dir_handle = null) {}
11+
public function close() {}
1312

1413
/**
15-
* @param resource|null $dir_handle
1614
* @return void
1715
* @implementation-alias rewinddir
1816
*/
19-
public function rewind($dir_handle = null) {}
17+
public function rewind() {}
2018

2119
/**
22-
* @param resource|null $dir_handle
2320
* @return string|false
2421
* @implementation-alias readdir
2522
*/
26-
public function read($dir_handle = null) {}
23+
public function read() {}
2724
}

ext/standard/dir_arginfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d8d8c93a1659e1790b25a65d7e1d0d7430724e9d */
2+
* Stub hash: a715bf6a8d5fe69732623cc17f03bd463f369648 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Directory_close, 0, 0, 0)
5-
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, dir_handle, "null")
65
ZEND_END_ARG_INFO()
76

87
#define arginfo_class_Directory_rewind arginfo_class_Directory_close

ext/standard/tests/directory/DirectoryClass_basic_001.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,19 @@ Class [ <internal%s> class Directory ] {
4141
- Methods [3] {
4242
Method [ <internal:standard> public method close ] {
4343

44-
- Parameters [1] {
45-
Parameter #0 [ <optional> $dir_handle = null ]
44+
- Parameters [0] {
4645
}
4746
}
4847

4948
Method [ <internal:standard> public method rewind ] {
5049

51-
- Parameters [1] {
52-
Parameter #0 [ <optional> $dir_handle = null ]
50+
- Parameters [0] {
5351
}
5452
}
5553

5654
Method [ <internal:standard> public method read ] {
5755

58-
- Parameters [1] {
59-
Parameter #0 [ <optional> $dir_handle = null ]
56+
- Parameters [0] {
6057
}
6158
}
6259
}

0 commit comments

Comments
 (0)