I was just wondering if there was any way to make my object return false if placed in an if statement. The reason is I’m making a custom exception class. I would like to be able to do something along the lines of
class Dog{
public function lookAround()
{
if(seeDog())
{
return bark;
}
else
{
return sit;
}
}
public function seeDog()
{
if(object == Dog)
{
return "husky";
}
else
{
return Dog_Exception(no_see);
}
}
}
I understand that this is a horrendously stupid example. However, the point is that as this object stands, the if(seeDog()) test will evaluate true for both string “husky” and for the Dog_Exception object. If at all possible, i’d like Dog_Exception to evaluate to false, if placed in an if condition. That way I wouldn’t have to, for example, use a construct like if(typeof(seeDog()) == Dog_Exception) etc. I doubt this is possible, but any help would be great. Thanks!
Why are you returning an exception? Shouldn’t you be throwing it?