Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *val
zend_throw_error(NULL, "Property queryString is read only");
return value;
}
cache_slot = NULL;
}
return zend_std_write_property(object, name, value, cache_slot);
}
Expand Down
27 changes: 27 additions & 0 deletions ext/pdo/tests/gh17346.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-17346 (PDOStatement::$queryString "readonly" is not properly implemented)
--EXTENSIONS--
pdo
--SKIPIF--
<?php
$dir = getenv('REDIR_TEST_DIR');
if (false != $dir) die('skip is driver independent');
?>
--FILE--
<?php
$stmt = new PDOStatement();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it even legal to manually construct a PDOStatement?! I'm not sure if this is worth fixing, since for “properly created” PDOStatements writing just fails.

In fact, can't we just make it properly readonly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer to both your questions appears to be: mocking, see https://bugs.php.net/81084

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer to both your questions appears to be: mocking, see

sigh

Then we might be able to public public(set) readonly nowadays?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively making it public protected(set) readonly (i.e. readonly) and asking folks to go through Reflection for this kind of use case might also be okay.

try {
for ($i = 0; $i < 10; $i++) {
$stmt->queryString = (string) $i;
}
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
var_dump($stmt);
?>
--EXPECTF--
Property queryString is read only
object(PDOStatement)#%d (1) {
["queryString"]=>
string(1) "0"
}