implementing PHP 8.1's array_column when used on an array of objects
I tried several approaches but none seem to work. I tried several approaches but none seem to work. I've been struggling with this for a few days now and could really use some help... I'm working with a question when trying to use the `array_column` function in PHP 8.1 on an array of objects. I have an array of user objects, and I want to extract the 'email' property from each object. However, the function seems to return an empty array instead of the expected list of emails. Hereβs the code Iβm working with: ```php class User { public $email; public function __construct($email) { $this->email = $email; } } $users = [ new User('alice@example.com'), new User('bob@example.com'), new User('charlie@example.com'), ]; $emails = array_column($users, 'email'); print_r($emails); ``` When I run this, I get an empty output: ``` Array ( ) ``` Iβve tried checking the properties of the objects directly and they seem fine. If I change the `User` class to use associative arrays instead, like this: ```php $users = [ ['email' => 'alice@example.com'], ['email' => 'bob@example.com'], ['email' => 'charlie@example.com'], ]; ``` then `array_column` works as expected: ```php $emails = array_column($users, 'email'); print_r($emails); ``` This outputs: ``` Array ( [0] => alice@example.com [1] => bob@example.com [2] => charlie@example.com ) ``` Is there a way to make `array_column` work directly with an array of objects in PHP 8.1? Or am I missing something important about how `array_column` works with objects? Any insights would be appreciated! Has anyone else encountered this? This is part of a larger application I'm building. I'm using Php LTS in this project. Cheers for any assistance! I recently upgraded to Php 3.10. What would be the recommended way to handle this?