Return list<mixed> from PDOStatement::fetchAll() in function signature map#5643
Return list<mixed> from PDOStatement::fetchAll() in function signature map#5643phpstan-bot wants to merge 5 commits into
list<mixed> from PDOStatement::fetchAll() in function signature map#5643Conversation
…`, and `pg_fetch_all_columns()` in function signature map - Change PDOStatement::fetchAll() return type from `array` to `list<mixed>` (PHP 8.0+) and from `array|false` to `list<mixed>|false` (pre-8.0) across all four overload variants - Change pg_fetch_all() return type from `array<non-empty-list<string|null>>` to `list<non-empty-list<string|null>>` - Change pg_fetch_all_columns() return type from `array|false` to `list<string|null>|false` - Change sqlite_fetch_all() return type from `array` to `list<mixed>` - All these functions return sequentially 0-indexed arrays, which are lists by definition - mysqli_fetch_all / mysqli_result::fetch_all were already correctly typed as `list<array>`
The default overload variant covers all fetch modes including FETCH_KEY_PAIR and FETCH_GROUP which return associative arrays, not lists. Only the specific overload variants (FETCH_COLUMN, FETCH_CLASS, FETCH_FUNC) are guaranteed to return lists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
list<mixed> from PDOStatement::fetchAll(), pg_fetch_all(), and pg_fetch_all_columns() in function signature maplist<mixed> from PDOStatement::fetchAll() in function signature map
…changes These functions should not have their return types narrowed to list: - pg_fetch_all/pg_fetch_all_columns: revert to original array types - sqlite_fetch_all: undocumented on php.net, keep as array Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… list Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
VincentLanglet
left a comment
There was a problem hiding this comment.
$stmt->fetchAll(\PDO::FETCH_COLUMN); is a valid call and returns a list.
Since both
$stmt->fetchAll(PDO::FETCH_ASSOC)
$stmt->fetchAll(\PDO::FETCH_COLUMN);
fallback to the same signature, I think we cannot solve this by changing the functionMap, but with a dedicated returnTypeExtension instead.
The function map alone cannot distinguish single-argument calls like fetchAll(PDO::FETCH_COLUMN) from fetchAll(PDO::FETCH_ASSOC) since both match the same default signature. This extension inspects the constant fetch mode value to determine whether the result is a list or array. Modes with FETCH_GROUP/FETCH_UNIQUE flags or FETCH_KEY_PAIR return associative arrays (not lists). All other known modes return lists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pushed. Here's what I did to address VincentLanglet's review: Created
This solves the reviewer's concern that Updated |
Fixes phpstan/phpstan#11889