Skip to content

Commit 9db3f18

Browse files
committed
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
2 parents 68f45c5 + beee995 commit 9db3f18

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ PHP NEWS
101101
that is not in the result set. (Ilia Alshanetsky)
102102
. Fixed bug GH-23962 (Destroying a persistent PDO instance rolls back a
103103
transaction still in use by another instance). (Lazizbek Ergashev)
104+
. Fixed PDO::setAttribute() installing a PDO::ATTR_STATEMENT_CLASS class
105+
whose constructor arguments it rejects. (Ilia Alshanetsky)
106+
. Fixed PDO::ATTR_STATEMENT_CLASS constructor_args type errors reporting
107+
"array given" regardless of the value passed. (Ilia Alshanetsky)
104108

105109
- PDO_Firebird:
106110
. Fixed bug GH-23758 (PDO_Firebird returns null for non-null empty BLOBs).

‎ext/pdo/pdo_dbh.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ PHP_METHOD(PDO, prepare)
638638
if ((item = zend_hash_index_find(Z_ARRVAL_P(value), 1)) != NULL) {
639639
if (Z_TYPE_P(item) != IS_ARRAY) {
640640
zend_type_error("PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given",
641-
zend_zval_value_name(value));
641+
zend_zval_value_name(item));
642642
RETURN_THROWS();
643643
}
644644
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
931931
zend_argument_type_error(value_arg_num, "User-supplied statement class cannot have a public constructor");
932932
return false;
933933
}
934+
item = zend_hash_index_find(Z_ARRVAL_P(value), 1);
935+
if (item != NULL && Z_TYPE_P(item) != IS_ARRAY) {
936+
zend_argument_type_error(value_arg_num, "PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given",
937+
zend_zval_value_name(item));
938+
return false;
939+
}
934940
dbh->def_stmt_ce = pce;
935941
if (!Z_ISUNDEF(dbh->def_stmt_ctor_args)) {
936942
zval_ptr_dtor(&dbh->def_stmt_ctor_args);
937943
ZVAL_UNDEF(&dbh->def_stmt_ctor_args);
938944
}
939-
if ((item = zend_hash_index_find(Z_ARRVAL_P(value), 1)) != NULL) {
940-
if (Z_TYPE_P(item) != IS_ARRAY) {
941-
zend_argument_type_error(value_arg_num, "PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given",
942-
zend_zval_value_name(value));
943-
return false;
944-
}
945+
if (item != NULL) {
945946
ZVAL_COPY(&dbh->def_stmt_ctor_args, item);
946947
}
947948
return true;

‎ext/pdo/tests/pdo_030.phpt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ echo "===QUERY===\n";
7575
var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS));
7676
$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatementx', array($db)));
7777
var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS));
78+
try {
79+
$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, 'invalid-args']);
80+
} catch (TypeError $e) {
81+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
82+
}
83+
var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS));
84+
try {
85+
$db->prepare('SELECT * FROM test030', [PDO::ATTR_STATEMENT_CLASS => [PDOStatement::class, 'invalid-args']]);
86+
} catch (TypeError $e) {
87+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
88+
}
7889
$stmt = $db->query('SELECT * FROM test030');
7990
var_dump(get_class($stmt));
8091
var_dump(get_class($stmt->dbh));
@@ -112,6 +123,18 @@ array(2) {
112123
}
113124
}
114125
}
126+
TypeError: PDO::setAttribute(): Argument #2 ($value) PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, string given
127+
array(2) {
128+
[0]=>
129+
string(13) "PDOStatementX"
130+
[1]=>
131+
array(1) {
132+
[0]=>
133+
object(PDODatabase)#%d (0) {
134+
}
135+
}
136+
}
137+
TypeError: PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, string given
115138
PDODatabase::query()
116139
PDOStatementX::__construct()
117140
string(13) "PDOStatementX"

0 commit comments

Comments
 (0)