Reflection parameter type could be more precise about specific BackedEnum::from() and tryFrom() type
Nessuno ha ancora preso questa issue.
- #18016 di @DanielEScherzer — chiusa senza merge
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.2k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
Description
The following code:
<?php
declare(strict_types=1);
enum IntBacked: int {
case One = 1;
}
$rm = new ReflectionMethod(IntBacked::class, 'tryFrom');
var_export((string) $rm->getParameters()[0]->getType());
Resulted in this output:
'string|int'
But I expected this output instead:
'int'
Because when a bad type is passed in there, it's rejected with TypeError:
Argument #1 ($value) must be of type int, string given
Related: https://github.com/php/php-src/issues/12863
PHP Version
PHP 8.1+
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
Inizia eseguendo lo snippet PHP fornito e seguendo ReflectionMethod::getParameters() per lo specifico punto di ingresso BackedEnum::tryFrom(). Conferma che la reflection riporti int per IntBacked::tryFrom(), mentre il passaggio di una stringa produca comunque il TypeError mostrato; nell’issue non è indicato alcun percorso di file sorgente o di test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, 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