Unexpected behavior when using array_unique with objects in PHP 8.1
I'm encountering a puzzling issue when using `array_unique` to filter an array of objects in PHP 8.1. I have an array of user objects, and I want to get unique users based on their email addresses. However, when I apply `array_unique`, it seems to not work as expected, returning duplicate entries instead. Here's the code I'm using: ```php class User { public $name; public $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } } $users = [ new User('Alice', 'alice@example.com'), new User('Bob', 'bob@example.com'), new User('Alice', 'alice@example.com'), new User('Charlie', 'charlie@example.com') ]; $uniqueUsers = array_unique($users); ``` When I run this code, I expect `$uniqueUsers` to contain only two entries (the unique user objects). However, I'm getting all four objects back. The reason is probably that `array_unique` checks for equality based on the object references, not their properties. I've tried using a custom function with `array_map` to extract the emails first, but it feels a bit clunky. Is there a more elegant way to achieve uniqueness based on an object's property, such as the email, without losing the object references? Any advice or best practices would be greatly appreciated! This is part of a larger service I'm building. Is there a better approach?