Assigning property value through readonly array results in "Cannot modify readonly property"
まだ誰も着手していません。
評価
調査の方向性
まず、提供された再現コードを PHP 8.2.23 と 8.3.11 で実行し、一時変数を介したリファクタリング後のアクセスと比較します。PHP インタープリターで、直接の $a->[0]->b 式に対する readonly プロパティの処理を追跡します。直接代入によって B::$b が更新され、致命的なエラーなしで bar が出力されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
The following code:
<?php
class A {
public function __construct(
public readonly array $a,
) {}
}
class B {
public function __construct(
public string $b,
) {
}
}
$a = new A([ new B('foo') ]);
$a->a[0]->b = 'bar';
echo $a->a[0]->b;
Resulted in this output:
PHP Fatal error: Uncaught Error: Cannot modify readonly property A::$a in /test.php:17
But I expected this output instead:
bar
If you try to change the property of an object that is inside a readonly array, based on syntax it thinks you're change the array itself and throws a Fatal, even though that property we're actually trying to change ($a->a[0]->b) is not readonly and can be changed. If the code to change the B::$b property is refactored like this the code works as expected:
$a = new A([ new B('foo') ]);
$b = $a->a[0];
$b->b = 'bar';
PHP Version
8.2.23, 8.3.11
Operating System
No response
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 103
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
php/php-src のほかの issue
-
Bug SAPI: cli_server Status: Verified
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
Bug Status: Needs Triage
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Bug Category: Tests Status: Verified
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
似ている issue
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
FujiNetWIFI/fujinet-firmware#1649 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
HarbourMasters/Shipwright#7229 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
riscv-software-src/riscv-isa-sim#2435 · コメント 1 件 ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100