phpoperator-keywordoperator-precedence

When echoing boolean false, no text is printed


I found this question at http://www.phpinterviewquestions.com/php-interview-questions/operator-precedence/

Following operations are true or false? (Operator Precedence)

$one = true;
$two = null;
$a = isset($one) && isset($two);
$b = isset($one) and isset($two);

echo $a.'<br>';
echo $b;

I tried the above code. But only $b gets echoed as 1 (which is true). $a is not getting echoed. What could be the reason? I was expecting $a to be 0 (false).


Solution

  • It's not about precedence, it's about implicit type casting

    Use var_dump($a); instead of echo $a;

    $a actually is false, but being echo'ed false is casted to empty string.