Re: Discussion - Anti-null coercion
| From: | Sergii Shymko | Date: | Sun, 29 Oct 2023 20:33:04 +0000 |
| Subject: | Re: Discussion - Anti-null coercion | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121515@lists.php.net to get a copy of this message | ||
On Oct 29, 2023, at 3:23 PM, Robert Landers <landers.robert@gmail.com<mailto:landers.robert@gmail.com>> wrote:
Because falsy is different than null/non-existent. The closest
equivalent is "array_key_exists" (instead of empty/isset) but this
proposal isn't just applicable to arrays. I run into this pattern of
"if not null, then do something with the value" pretty often and it is
tedious to type it out.
In terms of falsy values, null coalescing operator ?? is a syntactic sugar for isset().
So, ?! operator will be equivalent to !isset() expression in the ternary.
For the reference:
https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op