OK, first, this is very special problem. I was working on PHP for long time, and I don’t know why this happened.
I have a function adminUpdate. This function will return true. I set it always return true for testing.
Then I have function take that result.
static function result2JSON($result,$options = array()) {
if($result == "permission") {
echo "permission";
}
if($result == true) {
echo "true";
}
switch ($result) {
case 'permission':
die($result."xxx permission");
$json = self::setJSON("Permission");
break;
case 'exist':
$json = self::setJSON("Exist");
break;
case false:
$json = self::setJSON("Error");
break;
case "":
$json = self::setJSON("Error");
break;
case 1 :
$json = self::setJSON("OK");
break;
case true:
$json = self::setJSON("OK");
break;
default:
$json = self::setJSON("OK");
break;
}
$json = array_merge($json,$options);
return $json;
}
These “Echo” use for testing on this case.
So, $result always = true before taken by this function.
But this is output I got:
permissiontrueResult = 1 IN permission section
That mean the $result = Permission , and then == true, and then == “permission” on switch.
Why is that ?
You may want to use identity check === rather than a check for equality.
In php, a non empty string is interpreted as true.
Take a Look at Boolean page on php.net (Short) http://php.net/manual/en/language.types.boolean.php
and the PHP Comparison Operators page…
http://www.php.net/manual/en/language.operators.comparison.php