From 0e972cf2cb1b826c7e00923b4d66f7fa4e688131 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Wed, 8 Jul 2026 21:23:30 +0530 Subject: [PATCH 1/3] 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/3] 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 e8b1aacad67edafc0453bd8116f15cc0b8c9edb1 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Wed, 8 Jul 2026 22:22:27 +0530 Subject: [PATCH 3/3] ext/spl: Narrow tentative return types for DirectoryIterator methods ext/spl: Narrow tentative return types for DirectoryIterator methods Add tentative return type to Directory::current() Add tentative return type to Directory::current() Add tentative return type to Directory::current() --- ext/phar/tests/phar_oo_004.phpt | 4 ++-- .../tests/ReflectionMethod_tentative_return_type.phpt | 6 +++--- ext/spl/spl_directory.c | 2 +- ext/spl/spl_directory.stub.php | 6 +++--- ext/spl/spl_directory_arginfo.h | 10 +++++----- ext/spl/tests/dit_004.phpt | 8 ++++---- 6 files changed, 18 insertions(+), 18 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/reflection/tests/ReflectionMethod_tentative_return_type.phpt b/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt index 05d18084f210..8968c5e58b57 100644 --- a/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt +++ b/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt @@ -59,11 +59,11 @@ string(%d) "Method [ sta bool(false) bool(true) string(0) "" -string(37) "SplFileInfo|FilesystemIterator|string" -string(191) "Method [ public method current ] { +string(25) "SplFileInfo|static|string" +string(179) "Method [ public method current ] { - Parameters [0] { } - - Tentative return [ SplFileInfo|FilesystemIterator|string ] + - Tentative return [ SplFileInfo|static|string ] } " 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..57407007c0a5 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -124,10 +124,10 @@ public function rewind(): void {} public function valid(): bool {} /** @tentative-return-type */ - public function key(): string {} + public function key(): int|string {} /** @tentative-return-type */ - public function current(): string|SplFileInfo|RecursiveDirectoryIterator {} + public function current(): string|SplFileInfo|static {} /** @tentative-return-type */ public function next(): void {} @@ -175,7 +175,7 @@ public function rewind(): void {} public function key(): string {} /** @tentative-return-type */ - public function current(): string|SplFileInfo|FilesystemIterator {} + public function current(): string|SplFileInfo|static {} /** @tentative-return-type */ public function getFlags(): int {} diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index c04e53a29f9b..3a5bd37d49d5 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: de8ef9b284ceb46a1d55b22d4a5a3009d04bc2af */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -103,9 +103,10 @@ 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_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) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_DirectoryIterator_current, 0, 0, SplFileInfo, MAY_BE_STRING|MAY_BE_STATIC) ZEND_END_ARG_INFO() #define arginfo_class_DirectoryIterator_next arginfo_class_DirectoryIterator_rewind @@ -125,8 +126,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_FilesystemIterator_key arginfo_class_SplFileInfo_getPath -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_FilesystemIterator_current, 0, 0, SplFileInfo|FilesystemIterator, MAY_BE_STRING) -ZEND_END_ARG_INFO() +#define arginfo_class_FilesystemIterator_current arginfo_class_DirectoryIterator_current ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_FilesystemIterator_getFlags, 0, 0, IS_LONG, 0) 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)