Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-07 Thread tyson andre
Hi Levi Morrison, > A bit off topic, but not entirely: > > In my opinion, adding another flag isn't the _real_ fix. Any function > which does comparisons should take a callable for users to provide any > comparison they wish. An iteratively better API would be: > >     function array_unique(list

Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-07 Thread Ilija Tovilo
To avoid noise I will respond to all e-mails at once. --- Hi someniatko > Perhaps an alternative idea is to provide a default string value for > enums which are not baked, > Nikolas had already brought up this idea earlier. As others have mentioned, this opens the door for type coercion issues

Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-07 Thread Levi Morrison via internals
A bit off topic, but not entirely: In my opinion, adding another flag isn't the _real_ fix. Any function which does comparisons should take a callable for users to provide any comparison they wish. An iteratively better API would be: function array_unique(list $array, callable(T $a, T $b):

Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-04 Thread Christoph M. Becker
On 04.11.2022 at 10:05, Rowan Tommins wrote: > On 3 November 2022 18:53:40 GMT, someniatko 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

Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-04 Thread Rowan Tommins
On 3 November 2022 18:53:40 GMT, someniatko 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

Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-03 Thread someniatko
> To solve this, I propose adding an ARRAY_UNIQUE_IDENTICAL option that > can be passed to array_uniques $flags which uses identical operator > (===) semantics. Internally it uses a new hashmap that allows using > arbitrary PHP values as keys to efficiently remove duplicates. This is > slightly

[PHP-DEV] ARRAY_UNIQUE_IDENTICAL option

2022-11-03 Thread Ilija Tovilo
Hi internals There's an open bug report that array_unique doesn't work for enums: https://github.com/php/php-src/issues/9775 This comes down to the fact that array_unique internally sorts the array before iterating over it to remove duplicates, and that enums are intentionally incomparable.