ext/spl: Narrow tentative return types for DirectoryIterator methods#22642
Open
arshidkv12 wants to merge 3 commits into
Open
ext/spl: Narrow tentative return types for DirectoryIterator methods#22642arshidkv12 wants to merge 3 commits into
arshidkv12 wants to merge 3 commits into
Conversation
jorgsowa
reviewed
Jul 8, 2026
|
|
||
| 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)); |
Contributor
There was a problem hiding this comment.
Why did you change the return data here? It's BC break.
Contributor
Author
There was a problem hiding this comment.
I changed it to match the TODO in the stub, but you're right—it changes the runtime behavior and is a BC break.
Member
There was a problem hiding this comment.
just few things.
- It breaks the "agreement" between
spl_filesystem_dir_current_keythat uses the integer index and this ::key() method. Maybe the stub should be fixed as to return int ? - If you want the current entry name, it seems
::getBasename()(::getFilename()eventually ?) is already doing it.
Contributor
Author
There was a problem hiding this comment.
class FilesystemIterator extends DirectoryIterator{
public function key(): string {}
}
class DirectoryIterator extends SplFileInfo implements SeekableIterator{
public function key(): int {}
}How to solve it?
Member
There was a problem hiding this comment.
class FilesystemIterator extends DirectoryIterator{ public function key(): string {} } class DirectoryIterator extends SplFileInfo implements SeekableIterator{ public function key(): int {} }How to solve it?
then int|string might work (current() would be string|SplFileInfo) ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update the
DirectoryIteratorstubs to narrow the tentative return typesof
key()andcurrent(), and regenerate the generated arginfo.