On 04.11.2022 at 10:05, Rowan Tommins wrote:

> On 3 November 2022 18:53:40 GMT, someniatko <somenia...@gmail.com> wrote:
>
>> You will have to memorize yet another PHP quirk, or be able to build a
>> logical chain:
>> - enums are non-comparable by default
>> - enums have no default string value (if not baked by a string)
>> - array_unique internally sorts an array
>> - default flag for array_unique compares the string representations of its 
>> items
>> - thus it won't work for enums in a general case
>
> Actually, I think this is already the case for "normal" objects - I had no 
> idea that array_unique used a string cast to compare objects, so am very 
> surprised that it will not consider objects of completely different classes 
> unique, if they happen to have the same string value: https://3v4l.org/UGCvB
>
> Making backed enums work with their backing value would be equally confusing 
> to me - Day::MONDAY and Month::JANUARY might both be backed by a 1, but they 
> are certainly distinct values. I'd much rather get an error that made me 
> check the manual and find a flag than have one of them silently discarded.

I agree.  In my opinion, we should *consider* to *always* raise a
warning on attempts to compare incomparable values.  As it is now,
silently returning false looks like a footgun to me.

--
Christoph M. Becker

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

Reply via email to