Skip to content

[5.x] Declare native return types on DatabaseIterator - #417

Open
Hackwar wants to merge 2 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-iterator-native-types
Open

Hackwar wants to merge 2 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-iterator-native-types

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

DatabaseIterator implements Iterator and Countable, but its six methods only carried #[\ReturnTypeWillChange], which suppresses PHP's tentative-return-type deprecation instead of fixing it. They now declare the interface return types: count(): int, current(): mixed, key(): mixed, next(): void, rewind(): void and valid(): bool. The attribute is removed. Subclasses that override these methods must add the same return types, hence 5.x.

This is the self-contained part of the review item "native types for DatabaseInterface, QueryInterface, StatementInterface and DatabaseIterator". Typing the three interfaces (about 150 methods, implemented by every driver, query and statement class and by third-party subclasses) needs agreement on the exact types first; see the report.

Testing Instructions

vendor/bin/phpunit and vendor/bin/phpunit -c phpunit.sqlite.xml.dist pass (DatabaseIteratorTest and the driver getIterator() tests), as do PHPStan and phpcs.

Documentation Changes Required

Entry "DatabaseIterator has native return types" in docs/v4-to-v5-update.md.

Depends on #410 (creates docs/v4-to-v5-update.md; this branch is based on it). Expect a trivial conflict in that file with the other 5.x PRs that append to it.

🤖 Generated with Claude Code

Hackwar and others added 2 commits November 12, 2026 23:48
Several 5.0 changes need an entry in the update guide; adding the empty
guide first keeps their pull requests from conflicting over its creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Iterator and Countable methods relied on #[\ReturnTypeWillChange], which
only defers PHP's tentative return type errors. They now declare the
interface return types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant