On Wed, Jun 22, 2022 at 8:27 PM Larry Garfield <la...@garfieldtech.com>
wrote:

>
> So I am firmly against making it easier to (mis)use enums in a situation
> where constants are already the superior solution by every metric.  The
> only argument I see is making case 1, transitioning from a string to an
> enum for a genuinely limited-case, easier.  But in that case, the
> transition is going to have to happen eventually anyway, and that means the
> type is going to change at some point, and the same BC issue will appear,
> just at a different time.  Unless the intent is to then never change the
> type and keep the function incorrectly typed (from the POV that it's
> logically an enum, even though string typed was the best/correct type for
> years) forever, in which case... use a set of constants.
>
>

Hi!
I'm with you on what you mentioned here.

But also, I think the need I understood arises from another case that is
neither 1 or 2.
When you have two domains the value might need to be represented as a
backed enum in one side and as a string in the other.
As far as I understood, this is the case, with applications that are in one
domain wants to have a proper enum for let's say the app roles as the
possible roles are just a limited set.
That application is using another library to configure the ACL using those
roles and this is another domain that does not have a limited value on the
role representation, it's just a string.
Naturally, you should just transform the enum instance to the string and
that should be done using the value property. But this does not work for
configurations done through attribute parameters.
And I think this is the only problem we should fix and that's fixable by
https://wiki.php.net/rfc/fetch_property_in_const_expressions

What you mentioned about developers using enum in the wrong way is
completely true and it's been a long effort for me in explaining this.
I was hoping it would be diminished somehow by increased popularity of
enums, now that they are supported by everyone. But the usages are also
increasing.

Regards,
Alex

Reply via email to