advanced patterns of PHP's `array_map` with Objects in PHP 8.1
Quick question that's been bugging me - I'm working on a personal project and I'm experiencing an unexpected scenario when using `array_map` in PHP 8.1 with an array of objects. I have a class `User` that has a method `getFullName()`, and I'm trying to use `array_map` to get an array of full names from an array of `User` objects. However, I keep getting an behavior that says `TypeError: array_map() expects parameter 1 to be a valid callback`. Here's the relevant code snippet: ```php class User { private $firstName; private $lastName; public function __construct($firstName, $lastName) { $this->firstName = $firstName; $this->lastName = $lastName; } public function getFullName() { return $this->firstName . ' ' . $this->lastName; } } $users = [ new User('John', 'Doe'), new User('Jane', 'Smith'), ]; $fullNames = array_map('User::getFullName', $users); ``` When I run this code, I receive the mentioned behavior. I expected `array_map` to call the `getFullName` method on each object in the `$users` array. I've tried changing the callback to an anonymous function: ```php $fullNames = array_map(function($user) { return $user->getFullName(); }, $users); ``` This works as intended, but I want to understand why the original approach failed. Is there a specific reason that `User::getFullName` is not a valid callback for `array_map`, and is there a way to use it directly? Also, are there any best practices for using method callbacks with `array_map` in cases like this? For context: I'm using Php on Ubuntu. This is happening in both development and production on CentOS.