Consider the following:
class MyClass
{
private $var1 = \"apple\";
private $var2 = \"orange\";
}
$obj = new MyClass();
if($obj) {
// do this
}
else
No, you can't. Unfortunately boolean casting in php is not modifiable, and an object will always return true when converted to a boolean.
Since you clearly have some logic you mean to place in that control statement, why not define a method on your object (say "isValid()" ) that checks the conditions you wish to check, and then replace:
if ($obj)
with:
if ($obj->isValid())