3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { public function __construct(public int $id) {} } class Admin { public function __construct(public int $id) {} } /** * @param User[] $users */ function deleteUsers(array $users) { $typedArray = (fn (User ...$users) => $users)(...$users); foreach ($typedArray as $user) { var_dump($user->id); } } deleteUsers([new User(1), new User(2), new User(3)]); deleteUsers([new User(4), new Admin(5), new User(6)]);

preferences:
25.93 ms | 404 KiB | 5 Q