I have encountered a very weird and concerning problem in some of my PHP code. A variable that I have returns true in an IF statement when it clearly should return false.
$pr = $_SESSION['fin_print_printer']; //this should equal 0
print $pr; //this returns 0, as it should
if($pr == "L"){
print "local";
} else {
print "serve";
}
print $pr; //this returns 0 again, as it should
This prints "local" in my script (in between the two zeros) and does not print "serve". With over 100,000 lines of code in my project, I've not experienced this issue yet, and now I can't figure out what is going on.
If I do if($pr === "L"), then it works as expected, but the above does not.
$prIS0as you state, it's logically impossible for 0 to == "L"if ($pr === "L")==or===shouldn't matter in this case$pris an integer variable. If you compare with==PHP will attempt to cast "L" to an integer, obtaining a value of 0, which is equal to the value of$pr. If you compare with===the test will fail because the types differ.