Improve incompatible trait property error message
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 results in a PHP Fatal Error:
trait FooTrait
{
private array $options = [];
}
class Foo
{
use FooTrait;
public function __construct(private array $options = []) {}
}
The error thrown is
PHP Fatal error: Foo and FooTrait define the same property ($options) in the composition of Foo. However, the definition differs and is considered incompatible.
However, the same thing defined in the class instead of in the constructor works:
trait FooTrait
{
private array $options = [];
}
class Foo
{
use FooTrait;
private array $options = [];
}
As does the same thing, but without setting a default value:
trait FooTrait
{
private array $options;
}
class Foo
{
use FooTrait;
public function __construct(private array $options) {}
}
This seems to be ane rror
PHP Version
PHP 8.1.29 to PHP 8.4.0-dev
Operating System
MAC OSX 14.7
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
Nell’issue non sono identificati né un file sorgente né un test. Riproduci gli esempi nelle versioni di PHP elencate, quindi traccia la composizione delle proprietà dei trait con le proprietà promosse dal costruttore; il lavoro è terminato quando il comportamento delle proprietà incompatibili è corretto e coperto da un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100