[PHP-CVS] [php-src] master: ext/spl: Narrow tentative return types for DirectoryIterator methods (#22642)

[email protected] (Arshid via GitHub)
Newsgroups php.cvs
Message-ID <[email protected]>
Author: Arshid (arshidkv12)
Committer: GitHub (web-flow)
Pusher: kocsismate
Date: 2026-08-15T14:31:09+02:00

Commit: https://github.com/php/php-src/commit/1f0e6ef98a09641fca04ef286d1687c3fdaa3f85
Raw diff: https://github.com/php/php-src/commit/1f0e6ef98a09641fca04ef286d1687c3fdaa3f85.diff

ext/spl: Narrow tentative return types for DirectoryIterator methods (#22642)

Changed paths:
  M  UPGRADING
  M  ext/phar/tests/phar_oo_004.phpt
  M  ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt
  M  ext/spl/spl_directory.stub.php
  M  ext/spl/spl_directory_arginfo.h


Diff:

diff --git a/UPGRADING b/UPGRADING
index 8f588bbf877c..f61e175a65b8 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -205,6 +205,8 @@ PHP 8.6 UPGRADE NOTES
   . SplFileObject::next() past EOF no longer increments key() without bound.
     SplFileObject::seek() past EOF now produces the same key() value as
     SplTempFileObject; the two previously returned different values.
+  . DirectoryIterator::key() now returns int|string, 
+    and DirectoryIterator::current() returns string|SplFileInfo|static.
 
 - SimpleXML:
   . SimpleXMLElement::__construct() now raises a ValueError when the $data
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 [ <user, overwrites DateTimeZone, prototype DateTimeZone> sta
 bool(false)
 bool(true)
 string(0) ""
-string(37) "SplFileInfo|FilesystemIterator|string"
-string(191) "Method [ <internal:SPL, overwrites DirectoryIterator, prototype Iterator> public method current ] {
+string(25) "SplFileInfo|static|string"
+string(179) "Method [ <internal:SPL, overwrites DirectoryIterator, prototype Iterator> public method current ] {
 
   - Parameters [0] {
   }
-  - Tentative return [ SplFileInfo|FilesystemIterator|string ]
+  - Tentative return [ SplFileInfo|static|string ]
 }
 "
diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php
index 6194a8617b43..57407007c0a5 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(): int|string {}
 
-    /**
-     * @tentative-return-type
-     * @return DirectoryIterator
-     */
-    public function current(): mixed {} // TODO narrow return type
+    /** @tentative-return-type */
+    public function current(): string|SplFileInfo|static {}
 
     /** @tentative-return-type */
     public function next(): void {}
@@ -181,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 16860be558d7..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: 802429d736404c2d66601f640942c827b6e6e94b */
+ * 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,10 +103,11 @@ 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()
 
-#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, 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()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.