Commit 1f0e6ef98a0 for php.net
commit 1f0e6ef98a09641fca04ef286d1687c3fdaa3f85
Author: Arshid <arshidkv12@gmail.com>
Date: Sat Aug 15 18:01:09 2026 +0530
ext/spl: Narrow tentative return types for DirectoryIterator methods (#22642)
diff --git a/UPGRADING b/UPGRADING
index 8f588bbf877..f61e175a65b 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 097af93bbd9..09c941bd4b8 100644
--- a/ext/phar/tests/phar_oo_004.phpt
+++ b/ext/phar/tests/phar_oo_004.phpt
@@ -43,13 +43,13 @@ function valid(): bool
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 05d18084f21..8968c5e58b5 100644
--- a/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt
+++ b/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt
@@ -59,11 +59,11 @@ function printInfo(ReflectionMethod $methodInfo) {
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 6194a8617b4..57407007c0a 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 16860be558d..3a5bd37d49d 100644
Binary files a/ext/spl/spl_directory_arginfo.h and b/ext/spl/spl_directory_arginfo.h differ