Last active
December 29, 2015 08:19
-
-
Save nathanjohnson320/7642484 to your computer and use it in GitHub Desktop.
Why PHP is weird
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ("false" == true) echo "true\n"; | |
// => true | |
if ("false" == false) echo "true\n"; | |
// => false | |
if ("false" == 0) echo "true\n"; | |
// => true, wtf | |
if (false == 0) echo "true\n"; | |
// => true, as expected | |
// so "false" = true && "false" = 0, so "false" is true and | |
// false is false and we haven't even discussed identity, yet | |
if ((string)"false" === (int)0) echo "true\n"; | |
// => false, ...ok... | |
if ("0" === 0) echo "true\n"; | |
// => false | |
if ("false" === false) echo "true\n"; | |
// => false | |
if ((int)"0" === 0) echo "true\n"; | |
// => true, with type coercion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment