Fatal error: class and trait define the same constant in the composition of child class in case constant in trait is equal to constant in child class
オープン
まだ誰も着手していません。
Bug
Category: Engine
Status: Needs Triage
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
Description
The following code:
<?php
trait T {
public const a = C2::b;
}
class C1 {
use T;
const b = 1;
}
class C2 extends C1 {
use T;
const b = 2;
}
echo C1::a;
echo C2::a;
Resulted in this output:
Fatal error: C1 and T define the same constant (a) in the composition of C2. However, the definition differs and is considered incompatible. Class was composed in /in/riAnX on line 9
But I expected this output instead:
22
It's not clear to me why this code is incorrect, but at the same time, the following works:
<?php
trait T {
public const a = self::b;
}
class C1 {
use T;
const b = 1;
}
class C2 extends C1 {
use T;
const b = 2;
}
echo C1::a;
echo C2::a;
and outputs
11
PHP Version
8.2
Operating System
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ソースファイルもテストも指定されていません。まず、提供されている PHP 8.2 の reproducer を実行し、C2::b を使う trait 定数と self::b のバリアントを比較してください。trait とクラスの定数の構成を追跡して、意図されたルールを明らかにしてください。最初の例が意図された定数解決の動作に従い、誤った fatal error を発生させず、回帰テストのカバレッジがある状態が完了の条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100