Earlier quoted context omitted.
PHP: var_export(0 == "hello"); // true JavaScript: console.log(0 == "hello"); // false
Actually, I was hoping for something more than a single example. Or, did you mean that PHP and JavaScript were neck-and-neck all the way up to that one example, and ultimately it's the very one that proves PHP's type coercion is worse?
PHP: md5('240610708') == md5('QNKCDZO')
51–60 of 185 posts
Re: PHP: md5('240610708') == md5('QNKCDZO')
#52Earlier quoted context omitted.
Well, either in the example. Parent was saying "Reminds me on bash" For sh version, I'd go with super-safe: if test "x$1" = "x$2"
If you're doing that, even better to use "x${1}" to be safer. Also, conditional expressions ( [[ instead of [ or `test`) are generally a bit more well-behaved. See http://wiki.bash-hackers.org/syntax/ccmd/conditional_express... for more info.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#53So this is a PHP fail. But all the same, MD5 has been shown to fail collision resistance several times now.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#54I'm not exactly clear on how PHP == works, but you can see the MD5 for yourself: $ echo -n 240610708 | md5sum 0e462097431906509019562988736854 - $ echo -n QNKCDZO | md5sum 0e830400451993494058024219903391 - $ echo -n aabg7XSs | md5sum 0e087386482136013740957780965295 - All of them start with 0e, which makes me think that they're being parsed as floats and getting converted to 0.0. This is why "magic" operators like =…
When users started reporting that their logins would sometimes not work at the first time, I found out that strings that start with zero are coerced to 0 and then interpreted as false.
Never used PHP for anything important since.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#55I'm not exactly clear on how PHP == works, but you can see the MD5 for yourself: $ echo -n 240610708 | md5sum 0e462097431906509019562988736854 - $ echo -n QNKCDZO | md5sum 0e830400451993494058024219903391 - $ echo -n aabg7XSs | md5sum 0e087386482136013740957780965295 - All of them start with 0e, which makes me think that they're being parsed as floats and getting converted to 0.0. This is why "magic" operators like =…
Same goes for the `0E` prefix with an uppercase E The likelihood of generating a hash value with that kind of prefix is 2 in 65536. Finding a collision `hash(a) == hash(b)` with this "weak" equality comparison is approximately 1 in 256 if I'm not mistaken.
The probability of generating a hash with the right prefix is 10 in 16^3, or about 0.25%. Finding a 0e... == 0e... collision has probability ~6e-6, if both inputs are random. The chance that two hashes collide in this way given N random inputs is 1-(1-p)^(N-1), for N>0.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#56Earlier quoted context omitted.
> in_array(.., .., $strict) I think you're aware of the third parameter but for anyone who reads this post, it disables the type coercion of the in_array call.
Spoiling a good rant with facts.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#57Earlier quoted context omitted.
Same goes for the `0E` prefix with an uppercase E The likelihood of generating a hash value with that kind of prefix is 2 in 65536. Finding a collision `hash(a) == hash(b)` with this "weak" equality comparison is approximately 1 in 256 if I'm not mistaken.
> The likelihood of generating a hash value with that kind of prefix is 2 in 65536. The prefix is not sufficient though, the suffix must be entirely decimal otherwise it's not a valid number in scientific notation.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#58So this is a PHP fail. But all the same, MD5 has been shown to fail collision resistance several times now.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#59Earlier quoted context omitted.
> The likelihood of generating a hash value with that kind of prefix is 2 in 65536. The prefix is not sufficient though, the suffix must be entirely decimal otherwise it's not a valid number in scientific notation.
The prefix is sufficient. Any hash matching /0e[0-9].*/ works.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#60Earlier quoted context omitted.
Actually, you don't prefix with “x” to handle empty vars, but special characters, as Stephane Chazelas recently reminded: http://www.zsh.org/mla/workers/2015/msg00797.html
Again here conditional expressions should make this a non-issue ( [[ instead of [ ) since the stuff inside doesn't get parsed the same as general input. See http://wiki.bash-hackers.org/syntax/ccmd/conditional_express...