Skip to content

Commit 7eec281

Browse files
committed
Avoid UNKNOWN default in PDO::query()
1 parent 70a3a90 commit 7eec281

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

UPGRADING

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,11 @@ PHP 8.0 UPGRADE NOTES
350350
"exceptions". See https://www.php.net/manual/en/pdo.error-handling.php
351351
for details of behavior changes and how to explicitly set this attribute.
352352
RFC: https://wiki.php.net/rfc/pdo_default_errmode
353-
. The method PDOStatement::setFetchMode() now accepts the following signature:
353+
. The signatures of some PDO methods have changed:
354354

355-
PDOStatement::setFetchMode($mode, $classname, $params)
355+
PDO::query(
356+
string $statement, ?int $fetch_mode = null, ...$fetch_mode_args)
357+
PDOStatement::setFetchMode(int $mode, ...$params)
356358

357359
- PDO_ODBC:
358360
. The php.ini directive pdo_odbc.db2_instance_name has been removed

ext/pdo/pdo_dbh.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,13 @@ PHP_METHOD(PDO, query)
10261026
char *statement;
10271027
size_t statement_len;
10281028
zend_long fetch_mode;
1029+
zend_bool fetch_mode_is_null = 1;
10291030
zval *args = NULL;
10301031
uint32_t num_args = 0;
10311032
pdo_dbh_object_t *dbh_obj = Z_PDO_OBJECT_P(ZEND_THIS);
10321033
pdo_dbh_t *dbh = dbh_obj->inner;
10331034

1034-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l*", &statement, &statement_len, &fetch_mode, &args, &num_args)) {
1035+
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l!*", &statement, &statement_len, &fetch_mode, &fetch_mode_is_null, &args, &num_args)) {
10351036
RETURN_THROWS();
10361037
}
10371038

@@ -1061,7 +1062,7 @@ PHP_METHOD(PDO, query)
10611062

10621063
if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL)) {
10631064
PDO_STMT_CLEAR_ERR();
1064-
if (ZEND_NUM_ARGS() == 1 || SUCCESS == pdo_stmt_setup_fetch_mode(stmt, fetch_mode, args, num_args)) {
1065+
if (fetch_mode_is_null || SUCCESS == pdo_stmt_setup_fetch_mode(stmt, fetch_mode, args, num_args)) {
10651066

10661067
/* now execute the statement */
10671068
PDO_STMT_CLEAR_ERR();

ext/pdo/pdo_dbh.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function lastInsertId(?string $name = null) {}
3737
public function prepare(string $statement, array $driver_options = []) {}
3838

3939
/** @return PDOStatement|false */
40-
public function query(string $statement, int $fetch_mode = UNKNOWN, ...$fetch_mode_args) {}
40+
public function query(string $statement, ?int $fetch_mode = null, ...$fetch_mode_args) {}
4141

4242
/** @return string|false */
4343
public function quote(string $string, int $parameter_type = PDO::PARAM_STR) {}

ext/pdo/pdo_dbh_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: c329bfda55244467a2cd62f9d5c5120ec3f24eef */
2+
* Stub hash: 36270d1418fc4ddd8f79018372b0ef00fb6f5889 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0)
@@ -40,7 +40,7 @@ ZEND_END_ARG_INFO()
4040

4141
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_query, 0, 0, 1)
4242
ZEND_ARG_TYPE_INFO(0, statement, IS_STRING, 0)
43-
ZEND_ARG_TYPE_INFO(0, fetch_mode, IS_LONG, 0)
43+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fetch_mode, IS_LONG, 1, "null")
4444
ZEND_ARG_VARIADIC_INFO(0, fetch_mode_args)
4545
ZEND_END_ARG_INFO()
4646

ext/pdo/tests/bug_44173.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var_dump($stmt);
5454
--EXPECTF--
5555
Warning: PDO::query(): SQLSTATE[HY000]: General error: fetch mode doesn't allow any extra arguments in %s
5656
bool(false)
57-
PDO::query(): Argument #2 ($fetch_mode) must be of type int, string given
57+
PDO::query(): Argument #2 ($fetch_mode) must be of type ?int, string given
5858

5959
Warning: PDO::query(): SQLSTATE[HY000]: General error: too many arguments in %s
6060
bool(false)

0 commit comments

Comments
 (0)