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
Nessuno ha ancora preso questa issue.
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.1k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Non viene indicato alcun file sorgente né alcun test. Inizia eseguendo il reproducer fornito per PHP 8.2 e confronta la costante del trait che usa C2::b con la variante self::b; traccia la composizione delle costanti di trait e classe per stabilire la regola prevista. Il lavoro è completato quando il primo esempio segue il comportamento previsto per la risoluzione delle costanti senza generare un errore fatale errato, con copertura di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100