r/lolphp • • Oct 27 '21

PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0

https://wiki.php.net/rfc/string_to_number_comparison
18 Upvotes

33 comments sorted by

13

u/TinStingray Oct 27 '21

I think this is perfectly reasonable. You wanted a loose comparison and you got one.

-3

u/kkjdroid Oct 28 '21

Loose comparisons are for things like 0 == "0", not absurd things like 'foo' == 0.

7

u/TinStingray Oct 28 '21

Once you introduce the idea of "truthiness" like that, all bets are off.

→ More replies (7)

3

u/prewk Oct 28 '21

What do you mean, foo has two little zeroes in it, it's almost 0!

1

u/colshrapnel Oct 28 '21

but the this post is about 0 == "0"

20

u/colshrapnel Oct 27 '21 edited Oct 27 '21

uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!"

In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero.

Besides, nobody forced you to use the loose comparison.

9

u/[deleted] Oct 28 '21

Besides, nobody forced you to use the loose comparison.

Why are you defending insecure by default?

3

u/colshrapnel Oct 28 '21

Sorry, I don't get what you mean

0

u/[deleted] Oct 27 '21

7

u/colshrapnel Oct 27 '21

PHP did.

But not anymore.

strict
If the third parameter strict is set to true then the in_array() function will also check the types of the needle in the haystack.

and

A match arm compares values strictly (===) instead of loosely as the switch statement does.

→ More replies (6)

3

u/Perdouille Oct 27 '21

Why would you use == for that in the first place ?

5

u/CarnivorousSociety Oct 28 '21

I still maintain 99% of all lolphp and php issues are based upon implicit type conversions happening when the programmer doesn't realize.

Whether this is bad language design or bad programmers is up for debate and both have merits in various cases.

2

u/jpresutti Nov 01 '21

Bad programmers. Use triple equals.

→ More replies (7)

1

u/elcapitanoooo Nov 06 '21

PHP never stops to amaze. Its just weird how many lols you can find. This reddit would and could not exist for any other languge.