Created
March 15, 2013 08:16
-
-
Save janich/5168262 to your computer and use it in GitHub Desktop.
#FridayFun
Can you figure this out? :)
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
<?php | |
/* | |
* #FridayFun | |
* Can you figure this out :) | |
*/ | |
header("Content-type: text/plain; Charset=UTF-8"); | |
$str = "e903916d20ad926f38e239fbf0ba1923"; | |
$test = (int) $str; | |
echo "We have a string id:\n"; | |
var_dump($str); | |
echo "\nAnd when we cast it to (int), it becomes:\n"; | |
var_dump($test); | |
echo "\nNow lets see if they are the same ($str == $test):\n"; | |
if ($str == $test) { | |
echo "- Yes, they are the same!!"; // Wtf? | |
} else { | |
echo "- No, they're not the same."; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the question exactly?
If you want them to differ, you should check with if ($str === $test).
Else you are comparing a string with an integer:
string == integer
becomes
(int) string == integer
and of course that's true.