On 12 December 2022 22:20:27 GMT, Dan Liebner <dlieb...@gmail.com> wrote:
>Here's my biggest criticism: the change essentially forces this:
>$arr['key']
>
>to be rewritten as this (or some other intolerably bad alternative):
>isset($arr) && isset($arr['key']) && $arr['key']


Fortunately, this is not the case, the actual replacement code is this:

$arr['key'] ?? null

There has previously been a suggestion of introducing an even shorter syntax, 
such as this:

$arr[?'key']

(With the difference that only one key is marked optional, whereas ?? allows 
any number of dimensions - $foo['bar']['baz'] ?? null would be equivalent to 
$foo[?'bar'][?'baz'].)

This would avoid the inconsistency of configurable behaviour, and allow users 
to make clear with a single keystroke that they know a key might be missing, 
while giving them useful feedback for typos and other mistakes that lead to a 
key being unexpectedly missing.

I think this is a general approach that should be more explicitly embraced: 
introduce convenient syntax for valid use cases, while making accidents obvious.

Regards,
Hi Dan,
-- 
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to