Re: [RFC] Enumerations, Round 2

From: Date: Mon, 04 Jan 2021 15:21:42 +0000
Subject: Re: [RFC] Enumerations, Round 2
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-112750@lists.php.net to get a copy of this message
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

Thread (52 messages)

« previous php.internals (#112750) next »