Consider the following:
class MyClass
{
private $var1 = "apple";
private $var2 = "orange";
}
$obj = new MyClass();
if($obj) {
// do this
}
else {
// do that
}
PHP evaluates my object to true because it has member variables. Can this logic be overridden somehow? In other words, can I have control over what an object of my class will evaluate to when treated as a boolean?
See Question&Answers more detail:os