Re: RFC proposal for adding SORT_STRICT flag to array_unique()
| From: | Rob Landers | Date: | Sat, 25 Oct 2025 11:16:40 +0000 |
| Subject: | Re: RFC proposal for adding SORT_STRICT flag to array_unique() | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128964@lists.php.net to get a copy of this message | ||
On Sat, Oct 25, 2025, at 13:05, Morgan wrote:
> On 2025-10-25 21:23, Rob Landers wrote:
> >
> > Other than the bytes in memory and how they’re laid out, I fail to see
> > how 100 is different from 100. They’re conceptually identical, and
> > array_* functions generally behave by **value**, not by **identity**.
> >
>
> In the case of objects, "value" and "identity" are the same thing;
> without a __toString() method that always produces different strings for
> different objects, array_unique() can't be used to deduplicate an array
> of objects - which I find myself wanting to do on a fairly regular basis.
>
> ```
> $uniques = array_values(array_combine(array_map(spl_object_id(...),
> $source_array), $source_array));
> ```
>
Object identity and value are different things... https://3v4l.org/uZTsN
That’s literally the entire point of my original Records RFC: https://wiki.php.net/rfc/records — and a userland
implementation here: https://github.com/withinboredom/records along
with a few nice-to-haves https://github.com/withinboredom/common-records
— Rob