[php-src] PR #21434: Fix GH-20214: PDO::FETCH_DEFAULT unexpected behavior with setFetchMode
| From: | iliaal | Date: | Fri, 13 Mar 2026 22:57:30 +0000 |
| Subject: | [php-src] PR #21434: Fix GH-20214: PDO::FETCH_DEFAULT unexpected behavior with setFetchMode | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35196@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21434
Author: iliaal
When
setFetchMode(PDO::FETCH_DEFAULT) is called,
pdo_stmt_setup_fetch_mode() stores PDO_FETCH_USE_DEFAULT (0) as the
statement's default fetch type. Later, do_fetch() tries to resolve
PDO_FETCH_USE_DEFAULT by reading stmt->default_fetch_type — which is
also 0, creating a circular reference. On 8.4 this silently fell through to FETCH_BOTH;
on master it throws a ValueError.
The fix resolves PDO_FETCH_USE_DEFAULT to the connection-level default
(stmt->dbh->default_fetch_type) early in
pdo_stmt_setup_fetch_mode(), before flags extraction and the mode switch. The
connection default is guaranteed to never be PDO_FETCH_USE_DEFAULT (enforced by
PDO::setAttribute), so no circular resolution is possible.
Not sure if this should be rebased to the PHP-8.4 branch since the bug affects 8.4 as well (silently
returns wrong fetch mode there).
Fixes #20214