PHP 8.1 array_filter Returning Unexpected Results When Using a Callback Function with Object Properties
I'm migrating some code and I need some guidance on I'm maintaining legacy code that I'm dealing with I've looked through the documentation and I'm still confused about I'm facing an issue with `array_filter` in PHP 8.1 when trying to filter an array of objects based on properties. I have an array of user objects, and I want to filter out users who are inactive. My callback function seems to not be returning the expected results, and I'm getting users in my final array who I expected to be filtered out. Here's the code snippet I have: ```php class User { public $name; public $active; public function __construct($name, $active) { $this->name = $name; $this->active = $active; } } $users = [ new User('Alice', true), new User('Bob', false), new User('Charlie', true), new User('David', false) ]; $activeUsers = array_filter($users, function($user) { return $user->active; }); print_r($activeUsers); ``` When I run this code, I expect to see only Alice and Charlie in the filtered array, but when I print the result, it shows all users, but with only the active ones still having the same object references. The output looks like this: ``` Array ( [0] => User Object ( [name] => Alice [active] => 1 ) [1] => User Object ( [name] => Bob [active] => ) [2] => User Object ( [name] => Charlie [active] => 1 ) [3] => User Object ( [name] => David [active] => ) ) ``` I’ve also tried using `array_map` to set the properties to a boolean first, but that didn't work either. I double-checked that `active` is indeed a boolean value and not a string. Are there any nuances with `array_filter` that I might be missing, or could there be a specific issue with the way I'm defining my callback function? This is part of a larger API I'm building. Has anyone else encountered this? This is my first time working with Php LTS. Thanks for your help in advance! Could this be a known issue? Is there a simpler solution I'm overlooking?