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)]);
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
int(1) int(2) int(3) Fatal error: Uncaught TypeError: {closure}(): Argument #2 must be of type User, Admin given, called in /in/fjrcM on line 11 and defined in /in/fjrcM:11 Stack trace: #0 /in/fjrcM(11): {closure}(Object(User), Object(Admin), Object(User)) #1 /in/fjrcM(19): deleteUsers(Array) #2 {main} thrown in /in/fjrcM on line 11
Process exited with code 255.

preferences:
55.93 ms | 406 KiB | 5 Q