It's impossible to cast an object to a boolean related to a property inside the class because it always will return true. but I think you just need to create a function inside your class that allows you to return the boolean you need like this
public function bool()
{
return (count($this->array)>0);
}
when you need to use it, just call the function like this if ($obj->bool()) { ... }
and another way to make your statements look like what you wanted to do in the begining is to define a class with a really short name, I usually use _
, and this function should return the boolean you need just like this
function _ ($Obj)
{
return $Obj->bool();
}
finally, instead of testing on your class like this if ($class->bool())
which is a bit long, you do it like this
if (_($class))
{ /* do something fun */ }