-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null Coalescing Comparison #18104
Comments
Hi @miqrogroove. Please propose your idea to the internals mailing list. While feature requests are allowed here, this is primarily a bug tracker and feature requests are unlikely to get anywhere. I personally do not feel PHP needs more operators.
There is no perfect precedence. Precedence is set in a way that is expected to cause the least surprises, and require the fewest parentheses. But ultimately, it is subjective and may diverge from your expectation. Obviously, changing it now would have BC implications. |
I agree with not attempting to change operator precedence. I also think it's not about the shorter code. I would rather use two statements that make sense than one statement where I can't remember why I added parentheses. The |
Unfortunately, Tbh, |
Is the argument passing any different from the construct |
@miqrogroove Correct. |
I shall strive to use correct jargon in my mailing list messaging 🤓 |
Sent to the list and cross posted https://www.miqrogroove.com/blog/2025/functional-null-coalesce/ Closing here. |
Thanks @miqrogroove for the initiative! |
Description
A common challenge: Need to test the value of a variable whose existence is unknown.
Existing solutions:
Needed solution: What we don't have is an operator that will compare an uninitialized variable.
The other challenge: Null coalescing operator precedence causes unexpected behavior.
This requires an extra set of parentheses to be workable.
Further reading, 2017 Unary Null Coalescing
A unary operator would have been too easily confused for the binary operator. The question now is whether one or more comparison operators would be useful, and whether it requires things like
?!==
to be logically complete.The text was updated successfully, but these errors were encountered: