Search code examples
phpif-statementboolean-expression

Is it possible to make an object return false by default?


I tried to ask this before, and messed up the question, so I'll try again. Is it possible to make an object return false by default when put in an if statement? What I want:

$dog = new DogObject();
if($dog)
{
   return "This is bad;"
}
else
{
   return "Excellent!  $dog was false!"
}

Is there a way this is possible? It's not completely necessary, but would save me some lines of code. thanks!


Solution

  • No, PHP has no support for operator overloading. Maybe they'll add it in a future version.