Re: [RFC] Undefined Property Error Promotion
| From: | Guilliam Xavier | Date: | Tue, 19 Apr 2022 10:45:38 +0000 |
| Subject: | Re: [RFC] Undefined Property Error Promotion | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117541@lists.php.net to get a copy of this message | ||
On Sat, Apr 16, 2022 at 12:01 AM David Rodrigues <david.proweb@gmail.com>
wrote:
> > $foo[?'maynotexist'] // returns null and emits no warning
>
> In JS we have some like:
>
> foo['maynotexist']
> foo?.['maynotexist']
>
> In PHP could be:
>
> $foo['maynotexist']
> $foo?->['maynotexist']
>
You seem to be confusing two different things (in short, ?-> vs ->?):
1. In PHP *too* we *already* have "*nullsafe* property access"
$objectThatMayBeNull?->property (but no "nullsafe array access"
$arrayThatMayBeNull?['key'], see
https://wiki.php.net/rfc/nullsafe_operator#future_scope)
since PHP 8.0 (see
https://www.php.net/releases/8.0/en.php,
https://www.php.net/manual/en/migration80.new-features.php
etc.)
2. What may be proposed (in another RFC) is something like
$object->?propertyThatMayNotExist and/or $array[?'keyThatMayNotExist']
(call it e.g. "*lenient* property/array access"?) (JS is lenient by default)
But let's not deviate further.
Regards,
--
Guilliam Xavier