Skip to content

Commit 1fb2007

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

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
$dsn = 'sqlite::memory:';
35+
$pdo = method_exists('PDO', 'connect') ? PDO::connect($dsn) : new PDO($dsn);
36+
$sql = "SELECT 'dummy' pdo_fetch_class_type_class, 'bar' foo, 'dfg' abc;";
37+
38+
$fetchModes = [
39+
'PDO::FETCH_CLASS'
40+
=> PDO::FETCH_CLASS,
41+
'PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE'
42+
=> PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE,
43+
'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE'
44+
=> PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE,
45+
'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE'
46+
=> PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE,
47+
];
48+
49+
foreach ($fetchModes as $combinedModes => $fetchMode) {
50+
echo '## ' . $combinedModes . PHP_EOL;
51+
$db->query($sql)->fetchAll(
52+
$fetchMode,
53+
'dumpy',
54+
['constructor argument #1']
55+
);
56+
echo PHP_EOL;
57+
}
58+
?>
59+
--EXPECT--
60+
## PDO::FETCH_CLASS
61+
'pdo_fetch_class_type_class' = 'dummy'
62+
'foo' = 'bar'
63+
'abc' = 'dfg'
64+
constructor called,
65+
my class is 'dumpy'
66+
input parameters: array (
67+
0 => 'constructor argument #1',
68+
)
69+
70+
## PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE
71+
constructor called,
72+
my class is 'dumpy'
73+
input parameters: array (
74+
0 => 'constructor argument #1',
75+
)
76+
'pdo_fetch_class_type_class' = 'dummy'
77+
'foo' = 'bar'
78+
'abc' = 'dfg'
79+
80+
## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE
81+
'foo' = 'bar'
82+
'abc' = 'dfg'
83+
constructor called,
84+
my class is 'dummy'
85+
input parameters: array (
86+
0 => 'constructor argument #1',
87+
)
88+
89+
## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE
90+
constructor called,
91+
my class is 'dummy'
92+
input parameters: array (
93+
0 => 'constructor argument #1',
94+
)
95+
'foo' = 'bar'
96+
'abc' = 'dfg'

0 commit comments

Comments
 (0)