PHP 8.0 Comparison Change

Another new thing in PHP 8.0 will be slightly less madness in non strict value comparison.

Saner string to number comparisons

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

Here is the new table:

== true false 1 0 -1 '1' '0' '-1' NULL [] 'php' ''
true TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE
false FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE
1 TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
0 FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE
-1 TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
'1' TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
'0' FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
'-1' TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
NULL FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE TRUE
[] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE
'php' TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
'' FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE
Red: false everywhere
Green: true everywhere
Blue: true in <= 7.4, false in >= 8.0

Saner numeric strings

https://wiki.php.net/rfc/saner-numeric-strings

== 0 123 '123' '   123' '123   ' '   123   ' '123abc' 'abc123'
0 TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
123 FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
'123' FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
'   123' FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
'123   ' FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
'   123   ' FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
'123abc' FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
'abc123' FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
Red: false everywhere
Green: true everywhere
Blue: true in <= 7.4, false in >= 8.0
Gold: false in <= 7.4, true in >= 8.0

Comments

Comments powered by Disqus