-
Notifications
You must be signed in to change notification settings - Fork 8k
Coalesce operator #824
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
Coalesce operator #824
Conversation
|
Cool! |
|
I like the idea... but still think ?? is ugly :< |
|
Maybe $a = isset($b) && $b ? 'b' : 'c';
$a = $b ?? 'b' : 'c';
$a = isset($b) && $b ? $b : 'c';
$a = $b ??: 'c'; |
|
Considering that the basic purpose of a coalesce mechanism is to group questions and ORs... $a = $b ?| $c ?| $d ?| 'default';should be the equivalent of ... $a = (isset($b) && !!$b) ? $b : (isset($c) && !!$c ? $c : (isset($d) && !!$d ? $d : 'default'));As ? is a question mark and | is the OR symbol, combining them feels appropriate. I think using just symbols, we are going to be on a limited choice. Combining symbols would seem to be the only choice. And so, if the symbols used can relate to the use, then that should make it easier to understand. |
|
I agree in principle, but ?| is ugly. |
|
How about |
|
No. |
|
@TazeTSchnitzel what about |
|
How about |
|
@nikic Excellent, let's ship it. |
|
Let's just be honest here and say that |
|
@morrisonlevi C-C-C-C-C-C-C-C-C-COMBO BREAKERRRR |
|
|
|
@shoomyth Well, |
|
ok for so why not add also? $a ??= "something"; // which will be equivalent to $a = isset($a) ? $a : "something" ... |
👍 I already suggested it in original thread. |
|
Please stop making the same suggestions, it's hurting my sanity. |
|
Could we add another test case? Should output |
|
@datibbaw Sure thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class names are case-insensitive, it really doesn't matter.
|
@datibbaw Done. |
|
"string" . $array['undefined_key'] ?? "" . " another string" |
|
@adnen-chouibi try putting parentheses around the part following the period |
The patch for this RFC: https://wiki.php.net/rfc/isset_ternary