Last active
August 29, 2015 14:11
-
-
Save shello/1040d3f0e86a4a032436 to your computer and use it in GitHub Desktop.
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 | |
// via https://twitter.com/joswr1ght/status/544548300033363971 | |
var_dump(md5('240610708')); | |
// string(32) "0e462097431906509019562988736854" | |
var_dump(md5('QNKCDZO')); | |
// string(32) "0e830400451993494058024219903391" | |
var_dump(md5('240610708') == md5('QNKCDZO')); | |
// bool(true) | |
var_dump(md5('240610708') === md5('QNKCDZO')); | |
// bool(false) | |
// Why? | |
// $a == $b : TRUE if $a is equal to $b after type juggling. | |
// $a === $b : TRUE if $a is equal to $b, and they are of the same type. | |
// | |
// When Type Juggling for the comparison, if PHP sees a string that could be | |
// a float, it does treat it as a float. In this case, "0e"-something will | |
// always evaluate to 0 (as 0 × 10**n will always be 0), evaluating the | |
// comparison to TRUE: | |
var_dump("0e4" == "0e8"); | |
// bool(true) | |
var_dump("0e4" === "0e8"); | |
// bool(false) | |
// Reference: | |
// http://php.net/manual/en/language.operators.comparison.php | |
// http://php.net/manual/en/language.types.type-juggling.php | |
// http://php.net/manual/en/language.types.string.php#language.types.string.conversion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment