Exactly why does this work this way? (null coalescing operator precedence) [duplicate]
The null coalescence operator has a precedent that is different from most other comparators in PHP: Example 1: (Incorrect) $var['x'] = "5"; if ((int)$var['x']??0 < 1 ) { print "less than 1"; /* Outputs this */ } else { print "more than 1"; } This will result in "less" because the comparison seems to be between $var['x'] vs 0<1 but surely that would be $var['x']??(false) which still doesn't seem to me to warrant that if being true. Example 2: (Incorrect) $var['x'] = "5"; if ($var['x']??5 < 1 ) { print "less than 1"; /* Still outputs this */ } else { print "more than 1"; } I do understand the ex
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.