PDOStatement::$queryString "readonly" is not properly implemented
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$stmt = new PDOStatement();
var_dump($stmt);
for($i=0;$i<10;$i++)
$stmt->queryString = (string) $i;
var_dump($stmt);
Resulted in this output:
object(PDOStatement)#1 (0) {
["queryString"]=>
uninitialized(string)
}
object(PDOStatement)#1 (1) {
["queryString"]=>
string(1) "9"
}
But I expected this output instead:
object(PDOStatement)#1 (0) {
["queryString"]=>
uninitialized(string)
}
Fatal error: Uncaught Error: Property queryString is read only in x.php:5
The reason this happens is because the following code is wrong:
https://github.com/php/php-src/blob/209e0d6ad29b1f49982c58088aadd9d1ad86a162/ext/pdo/pdo_stmt.c#L2008-L2014
The second loop iteration just reuses the cache slot and won't go through the write handler, bypassing the fake readonly check.
Either this should be relaxed or be fixed (i.e. "real readonly").
PHP Version
8.3+
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading ext/pdo/pdo_stmt.c at the linked lines and run the reproduction from the issue. Done means repeated assignments to PDOStatement::$queryString no longer bypass the readonly check and produce the expected Error; an open pull request already addresses this issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100