Skip to content

Commit 91eb201

Browse files
committed
Allow initializing assignment to PDOStatement::$queryString
If the object is not created through PDO::prepare(), e.g. in a mock scenario, it should still be possible to initialize the $queryString property. See bug #81084.
1 parent 509d349 commit 91eb201

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

ext/pdo/pdo_stmt.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -2019,11 +2019,13 @@ PHP_METHOD(PDOStatement, getIterator)
20192019
static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *value, void **cache_slot)
20202020
{
20212021
if (zend_string_equals_literal(name, "queryString")) {
2022-
zend_throw_error(NULL, "Property queryString is read only");
2023-
return value;
2024-
} else {
2025-
return zend_std_write_property(object, name, value, cache_slot);
2022+
zval *query_string = OBJ_PROP_NUM(object, 0);
2023+
if (!Z_ISUNDEF_P(query_string)) {
2024+
zend_throw_error(NULL, "Property queryString is read only");
2025+
return value;
2026+
}
20262027
}
2028+
return zend_std_write_property(object, name, value, cache_slot);
20272029
}
20282030

20292031
static void dbstmt_prop_delete(zend_object *object, zend_string *name, void **cache_slot)

ext/pdo/tests/pdo_036.phpt

+19-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ $instance = new reflectionclass('pdostatement');
99
$x = $instance->newInstance();
1010
var_dump($x);
1111

12+
// Allow initializing assignment.
13+
$x->queryString = "SELECT 1";
14+
var_dump($x);
15+
// But don't allow reassignment.
16+
try {
17+
$x->queryString = "SELECT 2";
18+
var_dump($x);
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
1223
$instance = new reflectionclass('pdorow');
1324
$x = $instance->newInstance();
1425
var_dump($x);
@@ -19,9 +30,14 @@ object(PDOStatement)#%d (0) {
1930
["queryString"]=>
2031
uninitialized(string)
2132
}
33+
object(PDOStatement)#2 (1) {
34+
["queryString"]=>
35+
string(8) "SELECT 1"
36+
}
37+
Property queryString is read only
2238

23-
Fatal error: Uncaught PDOException: You may not create a PDORow manually in %spdo_036.php:8
39+
Fatal error: Uncaught PDOException: You may not create a PDORow manually in %spdo_036.php:%d
2440
Stack trace:
25-
#0 %spdo_036.php(8): ReflectionClass->newInstance()
41+
#0 %spdo_036.php(%d): ReflectionClass->newInstance()
2642
#1 {main}
27-
thrown in %spdo_036.php on line 8
43+
thrown in %spdo_036.php on line %d

0 commit comments

Comments
 (0)