PDO::query(): FETCH_CLASS constructor arguments error reports the wrong argument numbers
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Die falschen Zahlen kommen von der Konstruktorprüfung in pdo_stmt_setup_fetch_mode() in ext/pdo/pdo_stmt.c, die 3 und #2 fest codiert, obwohl die Funktion bereits constructor_arg_num und arg1_arg_num berechnet. Vergleiche diese Prüfung mit den anderen Fehlern in derselben Funktion und lies dann pdo_stmt_class_ctor_errors.phpt, um zu sehen, wie bestehende Fälle getestet werden. Fertig ist es, wenn der Fall PDO::query() Argument #4 und #3 meldet und die Ausgabe von setFetchMode() unverändert bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
PDO::query()reports the wrong argument numbers whenPDO::FETCH_CLASSgets constructor arguments for a class without a constructor.
The following code:
<?php
class NoCtor {}
$db = new PDO('sqlite::memory:');
try {
$db->query('SELECT 1', PDO::FETCH_CLASS, 'NoCtor', [1]);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
$db->query('SELECT 1', PDO::FETCH_CLASS, 'NotAClass');
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
Resulted in this output:
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()andPDOStatement::setFetchMode()sharepdo_stmt_setup_fetch_mode()inext/pdo/pdo_stmt.c. The callers pass the position of the fetch mode (1fromsetFetchMode(),2fromPDO::query()), and the function computesarg1_arg_numandconstructor_arg_numfrom it. All errors in the function use these values, except the constructor check, which hardcodes3and#2. That is only right forsetFetchMode().The message was added in 3ff7758bcf7 (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.phptcoversfetchAll()andsetFetchMode(), but notPDO::query().A fix is to use
constructor_arg_numandarg1_arg_numin 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).
Operating System
Debian 13 (php:8.5-cli Docker image)
- Vorherrschende Sprache
- C
- Sterne
- 41.8k
- Forks
- 8.6k
- Ø Merge
- 2 T. 15 Std.
- Gemergte PRs (30 T.)
- 125
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php/php-src
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)OffenExtension: openssl Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
php/php-src#25402 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
php/php-src#25397 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
SNMP accepts malformed remote portsEvtl. vergeben @somethingwithproof hat das vor 21 Tagen übernommen. Offen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 62/100
php/php-src#25137 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
php/php-src#24196 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
python-pillow/Pillow#10590 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
openwrt/packages#31407 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
CCExtractor/ccextractor#2478 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag