Re: ARRAY_UNIQUE_IDENTICAL option

From: Date: Fri, 04 Nov 2022 09:05:39 +0000
Subject: Re: ARRAY_UNIQUE_IDENTICAL option
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-118959@lists.php.net to get a copy of this message
On 3 November 2022 18:53:40 GMT, someniatko <someniatko@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]

« previous php.internals (#118959) next »