Consider the following:
class MyClass
{
private $var1 = \"apple\";
private $var2 = \"orange\";
}
$obj = new MyClass();
if($obj) {
// do this
}
else
Sorry for being late, but I just played with similar task and have made some kind of a hack/workaround. Notice "$object" pattern which calls __toString method.
class tst {
public $r = true;
function __toString() { return $this->r ? "1" : "0"; }
}
$object = new tst();
$object->r = true;
echo '
1: ';
if ("$object") echo 'true!'; else echo 'false!'; // "$object" becomes "1" == true
//echo "$object" ? 'true!' : 'false!';
$object->r = false;
echo '
0: ';
echo "$object" ? 'true!' : 'false!'; // "$object" becomes "0" == false
Output:
1: true!
0: false!