Tim Bezhashvyly:
Typed arrays exist in PHP, at least to some degree. This wonderful feature sneaked in as a side-effect of variadic functions that were added to the language in PHP 5.6.
Turns out one can actually typehint the variadic parameter, as so:
<?php
function foo (Product ...$products)
{
/* ... */
}
Only works if your function has one argument though (or if the “typed array” is the last parameter to your function). Otherwise you’ll get a Fatal Error Only the last parameter can be variadic
Leave a comment