I have a relatively simple function which uses a foreach
function foo($t) {
$result;
foreach($t as $val) {
$result = dosometh
Same problem. I've given up I simply manually code everything in the function.
This should give you the functionality you want:
function MyFunction($traversable)
{
if(!$traversable instanceof Traversable && !is_array($traversable))
{
throw new InvalidArgumentException(sprintf(
'Myfunction($traversable = %s): Invalid argument $traversable.'
,var_export($traversable, true)
));
}
}
EDIT
If you only want to display type of $traversable. And if you want the functionality inheritable in child classes.
public function MyMethod($traversable)
{
if(!$traversable instanceof Traversable && !is_array($traversable))
{
throw new InvalidArgumentException(sprintf(
'%s::MyMethod($traversable): Invalid argument $traversable of type `%s`.'
,get_class($this)
,gettype($traversable)
));
}
}