[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Tue, 29 Sep 2026 14:47:20 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141685@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-29T10:33:29-04:00 Commit: https://github.com/php/php-src/commit/9f6d3c318bb1166361832d27738c69f875cecfad Raw diff: https://github.com/php/php-src/commit/9f6d3c318bb1166361832d27738c69f875cecfad.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: ext/pdo: Keep statement class when ATTR_STATEMENT_CLASS is rejected Changed paths: M NEWS M ext/pdo/pdo_dbh.c M ext/pdo/tests/pdo_030.phpt Diff: diff --git a/NEWS b/NEWS index 9e4e2f40c45c..2e826b866444 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,12 @@ PHP NEWS . Fixed pcntl_signal_dispatch() dropping the signals queued behind a handler that throws. (nicolas-grekas) +- PDO: + . Fixed PDO::setAttribute() installing a PDO::ATTR_STATEMENT_CLASS class + whose constructor arguments it rejects. (Ilia Alshanetsky) + . Fixed PDO::ATTR_STATEMENT_CLASS constructor_args type errors reporting + "array given" regardless of the value passed. (Ilia Alshanetsky) + - PDO_PGSQL: . Fixed crash when a persistent connection fails. (KentarouTakeda) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 56320c3eb323..6b0d22d09399 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -631,7 +631,7 @@ PHP_METHOD(PDO, prepare) if ((item = zend_hash_index_find(Z_ARRVAL_P(value), 1)) != NULL) { if (Z_TYPE_P(item) != IS_ARRAY) { zend_type_error("PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given", - zend_zval_value_name(value)); + zend_zval_value_name(item)); RETURN_THROWS(); } ZVAL_COPY_VALUE(&ctor_args, item); @@ -924,17 +924,18 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value, u zend_argument_type_error(value_arg_num, "User-supplied statement class cannot have a public constructor"); return false; } + item = zend_hash_index_find(Z_ARRVAL_P(value), 1); + if (item != NULL && Z_TYPE_P(item) != IS_ARRAY) { + zend_argument_type_error(value_arg_num, "PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given", + zend_zval_value_name(item)); + return false; + } dbh->def_stmt_ce = pce; if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) { zval_ptr_dtor(&dbh->def_stmt_ctor_args); ZVAL_UNDEF(&dbh->def_stmt_ctor_args); } - if ((item = zend_hash_index_find(Z_ARRVAL_P(value), 1)) != NULL) { - if (Z_TYPE_P(item) != IS_ARRAY) { - zend_argument_type_error(value_arg_num, "PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given", - zend_zval_value_name(value)); - return false; - } + if (item != NULL) { ZVAL_COPY(&dbh->def_stmt_ctor_args, item); } return true; diff --git a/ext/pdo/tests/pdo_030.phpt b/ext/pdo/tests/pdo_030.phpt index 88308c18ca83..19cc059c9e6a 100644 --- a/ext/pdo/tests/pdo_030.phpt +++ b/ext/pdo/tests/pdo_030.phpt @@ -75,6 +75,17 @@ echo "===QUERY===\n"; var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS)); $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatementx', array($db))); var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS)); +try { + $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, 'invalid-args']); +} catch (TypeError $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS)); +try { + $db->prepare('SELECT * FROM test030', [PDO::ATTR_STATEMENT_CLASS => [PDOStatement::class, 'invalid-args']]); +} catch (TypeError $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} $stmt = $db->query('SELECT * FROM test030'); var_dump(get_class($stmt)); var_dump(get_class($stmt->dbh)); @@ -112,6 +123,18 @@ array(2) { } } } +TypeError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, string given +array(2) { + [0]=> + string(13) "PDOStatementX" + [1]=> + array(1) { + [0]=> + object(PDODatabase)#%d (0) { + } + } +} +TypeError: PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, string given PDODatabase::query() PDOStatementX::__construct() string(13) "PDOStatementX"

« previous php.cvs (#141685) next »