Re: ::from() and tryFrom() on Basic Enums
| From: | Rowan Tommins [IMSoP] | Date: | Wed, 09 Jul 2025 16:39:02 +0000 |
| Subject: | Re: ::from() and tryFrom() on Basic Enums | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127978@lists.php.net to get a copy of this message | ||
On 9 July 2025 17:12:52 BST, Rob Landers <rob@bottled.codes> wrote:
> I’ve been thinking of a “quality-of-life RFC” for obvious enums, for some time now.
> Basically, backed enums without a value receive the “obvious” value. So a string backed enum
> gets the name, while an int gets the ordered number.
I agree that this is a more fruitful direction. It allows users to say "the value of this case
*happens right now* to match its name", but still keeps name and value as strictly separate
concepts.
Importantly, it should be possible to mix default and non-default values on one enum, for
refactoring, e.g. you might want to change an auto-valued "case ZendFramework;" to an
explicit "case Laminas='ZendFramework';" or "case
ZendFramework='Laminas';" without rewriting all the other cases on the enum.
It could even be a specific short-hand syntax on the case, like "case ZendFramework =
auto" or "case ZendFramework = _".
Rowan Tommins
[IMSoP]