I just ran into an application problem where a query returns a string, but sometimes returns the value "0" as a legitimate string. This broke the logic in my application, and I can't find a fix. I found in the manual why it happens: http://www.php.net/manual/en/language.types.boolean.php
I'm using PHP 5.5.10 and normally all string values will cast bool(true) .... I found in the manual where you can explicitly cast a variable as a string. I put in some logic to do this.. but it also failed.
<?php
$str1 = "0";
//Below explicitly casts the string but it will still bool(false)
$str2 = (string) "0";
var_dump($str1);
var_dump((bool) $str1);
var_dump($str2);
var_dump((bool) $str2);
?>
The above test will show you that even explicit casting will not keep this string 'TRUE' in a boolean since. Below is where my problem is...
<?php
if($str)
{
//String is initialized, CODE to rip string is here
} else {
//Code for variable not initialized: NOTE: "0" or '0' will execute here!
}
?>
Can I somehow force PHP to see the string '0' or "0" to cast TRUE in a Boolean fashion?
I completely understand that an integer value 0 is false but the string thing threw me for a curve...