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.

Regards,

-- 
Rowan Tommins
[IMSoP]

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

Reply via email to