From 0e972cf2cb1b826c7e00923b4d66f7fa4e688131 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Wed, 8 Jul 2026 21:23:30 +0530 Subject: [PATCH 1/4] ext/spl: Narrow tentative return types for DirectoryIterator methods --- ext/spl/spl_directory.c | 2 +- ext/spl/spl_directory.stub.php | 14 ++++---------- ext/spl/spl_directory_arginfo.h | 8 ++++---- ext/spl/tests/dit_004.phpt | 8 ++++---- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index ccab32aec783..94e22469e586 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -749,7 +749,7 @@ PHP_METHOD(DirectoryIterator, key) ZEND_PARSE_PARAMETERS_NONE(); CHECK_DIRECTORY_ITERATOR_IS_INITIALIZED(intern); - RETURN_LONG(intern->u.dir.index); + RETURN_STRINGL(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name)); } /* }}} */ diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index 6194a8617b43..c1fc4ab5a7dd 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -123,17 +123,11 @@ public function rewind(): void {} /** @tentative-return-type */ public function valid(): bool {} - /** - * @tentative-return-type - * @return int - */ - public function key(): mixed {} // TODO change return type to string + /** @tentative-return-type */ + public function key(): string {} - /** - * @tentative-return-type - * @return DirectoryIterator - */ - public function current(): mixed {} // TODO narrow return type + /** @tentative-return-type */ + public function current(): string|SplFileInfo|RecursiveDirectoryIterator {} /** @tentative-return-type */ public function next(): void {} diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index 16860be558d7..c04e53a29f9b 100644 --- a/ext/spl/spl_directory_arginfo.h +++ b/ext/spl/spl_directory_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit spl_directory.stub.php instead. - * Stub hash: 802429d736404c2d66601f640942c827b6e6e94b */ + * Stub hash: 525bc52f78b08ba36d95559acb0b2cfd05d07711 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -103,10 +103,10 @@ ZEND_END_ARG_INFO() #define arginfo_class_DirectoryIterator_valid arginfo_class_SplFileInfo_isWritable -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DirectoryIterator_key, 0, 0, IS_MIXED, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_DirectoryIterator_key arginfo_class_SplFileInfo_getPath -#define arginfo_class_DirectoryIterator_current arginfo_class_DirectoryIterator_key +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_DirectoryIterator_current, 0, 0, SplFileInfo|RecursiveDirectoryIterator, MAY_BE_STRING) +ZEND_END_ARG_INFO() #define arginfo_class_DirectoryIterator_next arginfo_class_DirectoryIterator_rewind diff --git a/ext/spl/tests/dit_004.phpt b/ext/spl/tests/dit_004.phpt index c54d4bf3c0f6..cc07e714c19a 100644 --- a/ext/spl/tests/dit_004.phpt +++ b/ext/spl/tests/dit_004.phpt @@ -29,8 +29,8 @@ rmdir($dir); ?> --EXPECT-- bool(true) -int(0) -int(0) +string(1) "." +string(1) "." bool(true) -int(3) -int(3) +string(5) "file2" +string(5) "file2" \ No newline at end of file From 1538c2d6b50edb08cf112e82e12c28bc0984a681 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Wed, 8 Jul 2026 21:24:32 +0530 Subject: [PATCH 2/4] ext/spl: Narrow tentative return types for DirectoryIterator methods --- ext/spl/tests/dit_004.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/spl/tests/dit_004.phpt b/ext/spl/tests/dit_004.phpt index cc07e714c19a..9f52caf27cd4 100644 --- a/ext/spl/tests/dit_004.phpt +++ b/ext/spl/tests/dit_004.phpt @@ -33,4 +33,4 @@ string(1) "." string(1) "." bool(true) string(5) "file2" -string(5) "file2" \ No newline at end of file +string(5) "file2" From a2f5afbc7df2bedb6828e6c5d0408f07e2a04f6b Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Wed, 8 Jul 2026 22:22:27 +0530 Subject: [PATCH 3/4] ext/spl: Narrow tentative return types for DirectoryIterator methods --- ext/phar/tests/phar_oo_004.phpt | 4 ++-- ext/spl/spl_directory.c | 2 +- ext/spl/spl_directory.stub.php | 7 +++++-- ext/spl/spl_directory_arginfo.h | 5 +++-- ext/spl/tests/dit_004.phpt | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ext/phar/tests/phar_oo_004.phpt b/ext/phar/tests/phar_oo_004.phpt index 097af93bbd9d..09c941bd4b84 100644 --- a/ext/phar/tests/phar_oo_004.phpt +++ b/ext/phar/tests/phar_oo_004.phpt @@ -43,13 +43,13 @@ class MyDirectoryIterator extends DirectoryIterator return parent::valid(); } - function key(): mixed + function key(): int { echo __METHOD__ . "\n"; return parent::key(); } - function current(): mixed + function current(): MyDirectoryIterator { echo __METHOD__ . "\n"; return parent::current(); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 94e22469e586..ccab32aec783 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -749,7 +749,7 @@ PHP_METHOD(DirectoryIterator, key) ZEND_PARSE_PARAMETERS_NONE(); CHECK_DIRECTORY_ITERATOR_IS_INITIALIZED(intern); - RETURN_STRINGL(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name)); + RETURN_LONG(intern->u.dir.index); } /* }}} */ diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index c1fc4ab5a7dd..80b535b806aa 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -123,8 +123,11 @@ public function rewind(): void {} /** @tentative-return-type */ public function valid(): bool {} - /** @tentative-return-type */ - public function key(): string {} + /** + * @tentative-return-type + * @return int + */ + public function key(): mixed {} // TODO change return type to string /** @tentative-return-type */ public function current(): string|SplFileInfo|RecursiveDirectoryIterator {} diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index c04e53a29f9b..ade34b732f3d 100644 --- a/ext/spl/spl_directory_arginfo.h +++ b/ext/spl/spl_directory_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit spl_directory.stub.php instead. - * Stub hash: 525bc52f78b08ba36d95559acb0b2cfd05d07711 */ + * Stub hash: 72c5c46992a175ce75f25d02c6fd98adebefca5a */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -103,7 +103,8 @@ ZEND_END_ARG_INFO() #define arginfo_class_DirectoryIterator_valid arginfo_class_SplFileInfo_isWritable -#define arginfo_class_DirectoryIterator_key arginfo_class_SplFileInfo_getPath +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DirectoryIterator_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_DirectoryIterator_current, 0, 0, SplFileInfo|RecursiveDirectoryIterator, MAY_BE_STRING) ZEND_END_ARG_INFO() diff --git a/ext/spl/tests/dit_004.phpt b/ext/spl/tests/dit_004.phpt index 9f52caf27cd4..c54d4bf3c0f6 100644 --- a/ext/spl/tests/dit_004.phpt +++ b/ext/spl/tests/dit_004.phpt @@ -29,8 +29,8 @@ rmdir($dir); ?> --EXPECT-- bool(true) -string(1) "." -string(1) "." +int(0) +int(0) bool(true) -string(5) "file2" -string(5) "file2" +int(3) +int(3) From 793efeefee4a25f3a2fee92dd55affa3367e2212 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Thu, 9 Jul 2026 11:27:37 +0530 Subject: [PATCH 4/4] ext/spl: Narrow tentative return types for DirectoryIterator methods --- ext/spl/spl_directory.stub.php | 7 ++----- ext/spl/spl_directory_arginfo.h | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index 80b535b806aa..953069d7f51a 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -123,11 +123,8 @@ public function rewind(): void {} /** @tentative-return-type */ public function valid(): bool {} - /** - * @tentative-return-type - * @return int - */ - public function key(): mixed {} // TODO change return type to string + /** @tentative-return-type */ + public function key(): int|string {} /** @tentative-return-type */ public function current(): string|SplFileInfo|RecursiveDirectoryIterator {} diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index ade34b732f3d..7ffb51a62325 100644 --- a/ext/spl/spl_directory_arginfo.h +++ b/ext/spl/spl_directory_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit spl_directory.stub.php instead. - * Stub hash: 72c5c46992a175ce75f25d02c6fd98adebefca5a */ + * Stub hash: fee85b1938fe217aba54b1d6438dbe9034f6bbb1 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -103,7 +103,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_DirectoryIterator_valid arginfo_class_SplFileInfo_isWritable -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DirectoryIterator_key, 0, 0, IS_MIXED, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_DirectoryIterator_key, 0, 0, MAY_BE_LONG|MAY_BE_STRING) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_DirectoryIterator_current, 0, 0, SplFileInfo|RecursiveDirectoryIterator, MAY_BE_STRING)