php / php/php-src

PDOStatement::$queryString "readonly" is not properly implemented

Open
#17,346 2 comments 0 reactions 0 assignees View on GitHub

@ndossche is already working on this.

Since Oct 8, 2025.

  • #20111 by @ndossche — open
Bug Extension: pdo (core) Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.2k
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.