In some of my setters, I pass an array of objects. I would like to ensure that it only contains instances from a given class. Reading the doc, here is what I do :
class Foo
{
public function __construct()
{
}
}
class ErrorFoo
{
public function __construct()
{
}
}
$arrayObject = Array();
array_push($arrayObject, new Foo());
array_push($arrayObject, new Foo());
array_push($arrayObject, new ErrorFoo());
$error = false;
foreach ($arrayObject as $obj)
{
if ( $obj instanceof Foo )
{
echo "ok" . '<br>';
}
else
{
echo "error" . '<br>';
$error = true;
}
}
Do you know a simpler way than iterate through the array like this?
$error= true;helps.