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

From: Date: Tue, 29 Sep 2026 14:47:20 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141684@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-29T10:25:06-04:00 Commit: https://github.com/php/php-src/commit/9db3f189dcb6fd11976f8c2c2a7eca5b3a6b12ab Raw diff: https://github.com/php/php-src/commit/9db3f189dcb6fd11976f8c2c2a7eca5b3a6b12ab.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: ext/pdo: Keep statement class when ATTR_STATEMENT_CLASS is rejected # Conflicts: # ext/pdo/pdo_dbh.c 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 1b495b2d5074..5360f2b194f2 100644 --- a/NEWS +++ b/NEWS @@ -101,6 +101,10 @@ PHP NEWS that is not in the result set. (Ilia Alshanetsky) . Fixed bug GH-23962 (Destroying a persistent PDO instance rolls back a transaction still in use by another instance). (Lazizbek Ergashev) + . 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_Firebird: . Fixed bug GH-23758 (PDO_Firebird returns null for non-null empty BLOBs). diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 52486f337dd2..79c923442780 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -638,7 +638,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); @@ -931,17 +931,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 (#141684) next »