[php-src] Issue #8204: Nullsafe Operator doesn't work with uninitialized properties
| From: | iw-rylee | Date: | Thu, 17 Mar 2022 00:28:18 +0000 |
| Subject: | [php-src] Issue #8204: Nullsafe Operator doesn't work with uninitialized properties | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240369@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8204
Comment Author: iw-rylee
I think the biggest confusion here is that another operator interacting with
null
works:
```php
($this->date_val ?? null)?->format("Y-m-d") ?? "default"
```
This doesn't throw the error, but it's labelled as "Null coalescing operator"[
¶](https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op).
From that, I would think that something labelled "Nullsafe operator" [
¶](https://www.php.net/releases/8.0/en.php#nullsafe-operator) works with values/properties in the
same way.
It seems they have *very* similar naming but different underlying logic.
I understand that the documentation for "Null coalescing operator" explains that it's
essentially a replacement for cases where isset() is used with a ternary operator.
There doesn't seem to be the same level of documentation (that I could find easily) that
explains *how* the "Nullsafe operator" works.
For consistency, it seems sensible (to me at least) that either both throw an exception, or both
work.
Is there a reason one guards against IS_UNDEF and the other doesn't?