================================================================================ TYPED ARRAYS IN PHP ================================================================================ Date: 2020-10-13 Tags: php, software-design, clean-code URL: https://chemaclass.com/blog/typed-arrays-php/ -------------------------------------------------------------------------------- Argument unpacking, function variable argument list, and variadics function. Argument unpacking, function variable argument list, and variadics function. The perfect combination - Argument unpacking: Instead of passing the argument itself to the function, the elements it contains will be passed (as individual arguments). - Function variable argument list: The arguments will be passed into the given variable as an array. - Variadics function: Types can be checked with a type-hint. We will use this snippet for our examples. Having a class, Customer: new Customer("name-{$i}"), range(1, 6) ); Whenever we want to manipulate a list of Customers, we can pass as an argument: …$customers. HOW WE USED TO DO IT -------------------------------------------------------------------------------- We define the array type using the PHPDoc param comment block above. But we cannot define the real type of the item. The code will still run without any problem passing any type on that argument array $customers: