I don't know if this is of any help but by taking advantage of the __toString method you could possible achieve what you are looking for, but be warned, this is not at all clean code or best practice, the solution Rob suggested is actually better
You have to be using PHP5.2 or higher and take advantage of typecasting and the __toString magic method of PHP's class model
class Dummy
{
private $value;
public function __construct($val)
{
$this->value = $val;
}
public function __toString()
{
return $this->value;
}
}
$dummy = new Dummy('1');
if((string)$dummy) {
echo "__toString evaluated as true".PHP_EOL;
} else {
echo "__toString evaluated as false".PHP_EOL;
}
$dummy2 = new Dummy('0');
if((string)$dummy2) {
echo "__toString evaluated as true".PHP_EOL;
} else {
echo "__toString evaluated as false".PHP_EOL;
}
What happens here is the __toString method returns either the string 0 or string 1 (attention, don't return integers, return strings!)
'0' evaluates to false, '1' evaluates to true in if statement so it might be of help in your case too.