I am wondering (if possible) how you would declare an array of non-primitive class as a function parameter. For example
<?php
class C {}
function f(array C $c) {
/* use $c[1], $c[2]... */
}
Main fact - currently you can't type hint argument as array of something.
So you options are:
// just a function with some argument,
// you have to check whether it is array
// and whether each item in this array has type `C`
function f($c) {}
// function, which argument MUST be array.
// if it is not array - error happens
// you still have to check whether
// each item in this array has type `C`
function f(array $c) {}
// function, which argument of type CCollection
// So you have to define some class CCollection
// object of this class can store only `C` objects
function f(CCollection $c) {}
// class CCollection can be something like
class CCollection
{
private $storage = [];
function addItem(C $item)
{
$this->storage[] = $item;
}
function getItems()
{
return $this->storage;
}
}
iterable type hint: wiki.php.net/rfc/iterable
$c, you can directly dofunction f($c){ ... }, given that$cis an array of Class C objects.CCollectionwhich will store collection ofCobjectsfunction f(C $c) { .. }