- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- Array ( [0] => User Object ( ) [1] => User Object ( ) [2] => User Object ( ) )
<?php
class User {};
class UserList
{
private $list = [];
public function __construct(User ...$user)
{
$this->list = $user;
}
public function add(User $user)
{
$this->list[] = $user;
}
public function all(): array
{
return $this->list;
}
}
//
// Usage
//
$userList = new UserList(new User(), new User());
$userList->add(new User());
print_r($userList->all());