You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ValueError: PDO::query(): Argument #3 must be empty when class provided in argument #2 ($class) does not have a constructor
TypeError: PDO::query(): Argument #3 must be a valid class
But I expected this output instead:
ValueError: PDO::query(): Argument #4 must be empty when class provided in argument #3 ($class) does not have a constructor
TypeError: PDO::query(): Argument #3 must be a valid class
In PDO::query() the class is argument #3 (the second error says so) and the constructor arguments are argument #4.
PDO::query() and PDOStatement::setFetchMode() share pdo_stmt_setup_fetch_mode() in ext/pdo/pdo_stmt.c. The callers pass the position of the fetch mode (1 from setFetchMode(), 2 from PDO::query()), and the function computes arg1_arg_num and constructor_arg_num from it. All errors in the function use these values, except the constructor check, which hardcodes 3 and #2. That is only right for setFetchMode().
The message was added in 3ff7758 (GH-17427), so PHP 8.5 and later are affected. PHP 8.4 is not affected: it reports a different error for this case. pdo_stmt_class_ctor_errors.phpt covers fetchAll() and setFetchMode(), but not PDO::query().
A fix is to use constructor_arg_num and arg1_arg_num in this message. I have a patch with a test and will open a PR against PHP-8.5.
The quoted paragraphs were drafted with an LLM. The code and the output above come from real runs on PHP 8.4, 8.5 and 8.6.
PHP Version
PHP 8.5.12 (cli) (built: Oct 28 2026 01:20:43) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Also reproduced on PHP 8.6.0 and on the PHP-8.5 branch (8.5.14-dev).
Activity
Fix phpGH-25650: PDO::query() reports wrong argument numbers for ctor…
Fix phpGH-25650: PDO::query() reports wrong argument numbers for ctor…
Merge branch 'PHP-8.6' into fix/gh25379-array-map-foreach-optimization