- var_dump: documentation ( source)
<?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)]);