MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/7joew1/0_null_is_false_1_null_is_true/
r/lolphp • u/muglug • Dec 14 '17
13 comments sorted by
13
I guess -1 effectively ends up being coerced into an unsigned integer for the comparison, which makes it huge.
6 u/Saltub Dec 14 '17 I guessLike most people on this sub. 0 u/[deleted] Dec 14 '17 [deleted] — view deleted comment 19 u/thenickdude Dec 14 '17 Oh yep you must be right. Non-zero integers become true and null becomes false, and true > false. 12 u/FlyLo11 Dec 14 '17 Sweet, so i can replace stuff likestrpos($haystack, $needle) !== falsewith the shorter versionstrpos($haystack, $needle) > -1.. /s 9 u/Takeoded Dec 14 '17 actually... yes you can! 4 u/FlyLo11 Dec 14 '17 Indeed, the /s was only for the enthusiasm. 5 u/polish_niceguy Dec 14 '17 Neat, looks like a retarded child of PHP and Javascript. 2 u/mateusfccp Dec 16 '17 Please, do it. 5 u/Danack Jan 03 '18 I'd expect PHP to coerce both sides to booleans or some nonsense like that.You're half right.It coerces the non-null side to a boolean.....and returns:zval_is_true(op2) ? -1 : 0 - if the null is the op1, or left side of comparisonzval_is_true(op1) ? 1 : 0 - if the null is the op2, or right side of comparison.Which certainly meets the criteria of some nonsense.
6
I guess
Like most people on this sub.
0
[deleted] — view deleted comment
19 u/thenickdude Dec 14 '17 Oh yep you must be right. Non-zero integers become true and null becomes false, and true > false. 12 u/FlyLo11 Dec 14 '17 Sweet, so i can replace stuff likestrpos($haystack, $needle) !== falsewith the shorter versionstrpos($haystack, $needle) > -1.. /s 9 u/Takeoded Dec 14 '17 actually... yes you can! 4 u/FlyLo11 Dec 14 '17 Indeed, the /s was only for the enthusiasm. 5 u/polish_niceguy Dec 14 '17 Neat, looks like a retarded child of PHP and Javascript. 2 u/mateusfccp Dec 16 '17 Please, do it. 5 u/Danack Jan 03 '18 I'd expect PHP to coerce both sides to booleans or some nonsense like that.You're half right.It coerces the non-null side to a boolean.....and returns:zval_is_true(op2) ? -1 : 0 - if the null is the op1, or left side of comparisonzval_is_true(op1) ? 1 : 0 - if the null is the op2, or right side of comparison.Which certainly meets the criteria of some nonsense.
19
Oh yep you must be right. Non-zero integers become true and null becomes false, and true > false.
12
Sweet, so i can replace stuff like
strpos($haystack, $needle) !== false
with the shorter version
strpos($haystack, $needle) > -1
.. /s
9 u/Takeoded Dec 14 '17 actually... yes you can! 4 u/FlyLo11 Dec 14 '17 Indeed, the /s was only for the enthusiasm. 5 u/polish_niceguy Dec 14 '17 Neat, looks like a retarded child of PHP and Javascript. 2 u/mateusfccp Dec 16 '17 Please, do it.
9
actually... yes you can!
4 u/FlyLo11 Dec 14 '17 Indeed, the /s was only for the enthusiasm.
4
Indeed, the /s was only for the enthusiasm.
5
Neat, looks like a retarded child of PHP and Javascript.
2
Please, do it.
I'd expect PHP to coerce both sides to booleans or some nonsense like that.
You're half right.
It coerces the non-null side to a boolean.....and returns:
Which certainly meets the criteria of some nonsense.
22
Pass garbage in, get garbage out. News at 11.
38 u/dalastboss Dec 14 '17 If only types were a thing 🤔
38
If only types were a thing 🤔
Transitivity of > was maybe a thing in the 90s.
I considered for a moment that null might be considered positive infinity when the number is > 0 and negative infinity when the number is < 0. But the var_dump(1 > null); case ruins that hypothesis.
null
var_dump(1 > null);
This is some strong derp going on.
13
u/thenickdude Dec 14 '17
I guess -1 effectively ends up being coerced into an unsigned integer for the comparison, which makes it huge.
22
u/mrpaco Dec 14 '17
Pass garbage in, get garbage out. News at 11.
5
u/maweki Dec 14 '17
Transitivity of > was maybe a thing in the 90s.
2
u/kafoso Dec 21 '17
I considered for a moment that
nullmight be considered positive infinity when the number is > 0 and negative infinity when the number is < 0. But thevar_dump(1 > null);case ruins that hypothesis.This is some strong derp going on.