If I set $var to a string in PHP, that variable will evaluate to true in any conditions:
$var = "foo";
if ( $var ) {
echo 'I will be printed';
} else {
echo 'I will not be printed';
}
I understand that my condition above automatically does type juggling so that $var is converted in a bool.
Now, if I cast $var to an integer, I get 0:
var_dump( (int)$var ); // int(0)
0 is a falsy value which becomes false when converted to a bool:
$zero = 0;
var_dump( (bool)$zero ); // bool(false)
Considering the above, why doesn't my condition print "I will not be printed"?
intwhen the condition does the type juggling: it goes straight from astringto abool.