On Wed, Jun 22, 2022, at 2:31 PM, Alexandru Pătrănescu wrote:
> 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

Yes, I'm planing to vote +1 on that RFC.  Although in that case, the same logic 
for why to use a constant instead still applies.

> 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

I may need to publish a blog post on this issue specifically that Symfony and 
others can point to when people keep asking them to do the wrong thing.  I 
fully understand that major frameworks and libraries (Symfony et al) are 
getting the pushback of people trying to do the wrong thing, but the solution 
should be better educational efforts so people stop trying to do the wrong 
thing, not making it easier to do the wrong thing.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to