PHP is a weakly typed language, and does a lot of convenient type conversions. E.g., it'll convert this string variable $str
to a boolean when you try and use it in an IF statement:
$str = 'this is a string';
if ($str) {
echo 'str is true';
}
This automatic type casting can help one avoid writing a lot of explicit type casting code, but can also lead to unexpected behavior. For instance '0'
is a string containing the zero character, but PHP converts it to a boolean FALSE:
// this outputs bool(false)
$v = ('0' ? TRUE : FALSE); var_dump($v);
NogDog's links should provide a lot of helpful information.