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);

preferences:
40.19 ms | 733 KiB | 5 Q