php / php/php-src

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

オープン
#17,346 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

@ndossche がすでに取り組んでいます。

2025年10月8日 から。

  • #20111 @ndossche による — オープン
Bug Extension: pdo (core) Status: Verified
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、リンク先の行にある ext/pdo/pdo_stmt.c を読み、issue の再現を実行してください。PDOStatement::$queryString への繰り返しの代入が readonly チェックを回避せず、期待される Error を生成するようになれば完了です。この問題にはすでに対応するオープンな pull request があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。