3v4l.org

run code in 500+ PHP versions simultaneously
<?php class User { public function __construct(public readonly string $name) {} public function say() { echo $this->name, PHP_EOL; } } class Student extends User { // } function listAll(User ...$users) { array_map( callback: fn(User $user) => $user->say(), array: $users ); } $users = [ new User('Jhon'), new User('Jane'), new Student('Bob'), // Child Student Class works. //'not User Class', // passing anything other than class User will throw TypeError. ]; listAll(...$users);
Output for 8.1.30 - 8.1.34, 8.2.6 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Jhon Jane Bob

preferences:
49.29 ms | 744 KiB | 4 Q