Le 04/01/2021 à 16:12, Markus Fischer a écrit :
I can't say whether just : string is too much, but in general I like it.
I can follow the reasoning having no value by default and opt this in. The opt-in you suggested is very low-overhead (albeit a bit subtle, but maybe someone has a smarter idea :)
Maybe not evident, I like the enum RFC but think the most value for many use cases will having automatically values.
thanks!
- Markus
Hello,
I do not agree with having values per default, this is error prone in most of my use cases.
In most case where I need enums, I often need to replicate those in database too, or in message broker serialized messages: in this context, whenever I need to fix a typo in a enum case name, for example, if I use default values, I would have errors with my existing database records or live messages.
I prefer to keep an explicit switch/match to hydrate values from database or elsewhere, and use a value-less enum on the PHP side. Case names are the only semantically important value for the developer, and your code should not care about having a string value. In most cases only exchanges with the outside world in an heterogeneous environment (having a database makes it heterogeneous) care about having string values. In this case, I highly prefer having explicitely written (de)hydration code than automatic magic values happening over the place.
Cheers,
Pierre