Skip to content

Commit 3f8b4a9

Browse files
committed
Fix GH-20553: PDO::FETCH_CLASSTYPE ignores $constructorArgs in PHP 8.5.0
1 parent d13b5eb commit 3f8b4a9

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,10 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
771771
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified");
772772
goto in_fetch_error;
773773
}
774-
ctor_arguments = stmt->fetch.cls.ctor_args;
775774
}
776775
ZEND_ASSERT(ce != NULL);
776+
777+
ctor_arguments = stmt->fetch.cls.ctor_args;
777778
if (flags & PDO_FETCH_SERIALIZE) {
778779
if (!ce->unserialize) {
779780
/* As this option is deprecated we do not bother to mention the class name. */

ext/pdo/tests/gh20553.phpt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
--TEST--
2+
GH-20553: PHP 8.5.0 regression: PDO::FETCH_CLASSTYPE ignores $constructorArgs
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if (false == $dir) die('skip no driver');
9+
require_once $dir . 'pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
15+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
16+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
17+
$db = PDOTest::factory();
18+
19+
class dumpy {
20+
function __construct() {
21+
echo 'constructor called,' . PHP_EOL . ' my class is ' .
22+
var_export(get_class($this), true) . PHP_EOL .
23+
' input parameters: ' .
24+
var_export(func_get_args(), true) . PHP_EOL;
25+
}
26+
function __set($name, $value) {
27+
echo var_export($name, true) . ' = ' . var_export($value, true) .
28+
PHP_EOL;
29+
}
30+
}
31+
class dummy extends dumpy {
32+
}
33+
34+
$sql = "SELECT 'dummy' pdo_fetch_class_type_class, 'bar' foo, 'dfg' abc;";
35+
36+
$fetchModes = [
37+
'PDO::FETCH_CLASS'
38+
=> PDO::FETCH_CLASS,
39+
'PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE'
40+
=> PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE,
41+
'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE'
42+
=> PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE,
43+
'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE'
44+
=> PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE,
45+
];
46+
47+
foreach ($fetchModes as $combinedModes => $fetchMode) {
48+
echo '## ' . $combinedModes . PHP_EOL;
49+
$db->query($sql)->fetchAll(
50+
$fetchMode,
51+
'dumpy',
52+
['constructor argument #1']
53+
);
54+
echo PHP_EOL;
55+
}
56+
?>
57+
--EXPECT--
58+
## PDO::FETCH_CLASS
59+
'pdo_fetch_class_type_class' = 'dummy'
60+
'foo' = 'bar'
61+
'abc' = 'dfg'
62+
constructor called,
63+
my class is 'dumpy'
64+
input parameters: array (
65+
0 => 'constructor argument #1',
66+
)
67+
68+
## PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE
69+
constructor called,
70+
my class is 'dumpy'
71+
input parameters: array (
72+
0 => 'constructor argument #1',
73+
)
74+
'pdo_fetch_class_type_class' = 'dummy'
75+
'foo' = 'bar'
76+
'abc' = 'dfg'
77+
78+
## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE
79+
'foo' = 'bar'
80+
'abc' = 'dfg'
81+
constructor called,
82+
my class is 'dummy'
83+
input parameters: array (
84+
0 => 'constructor argument #1',
85+
)
86+
87+
## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE
88+
constructor called,
89+
my class is 'dummy'
90+
input parameters: array (
91+
0 => 'constructor argument #1',
92+
)
93+
'foo' = 'bar'
94+
'abc' = 'dfg'

0 commit comments

Comments
 (0)