Re: [RFC] Reclassifying engine warnings
| From: | Marco Pivetta | Date: | Thu, 12 Sep 2019 13:33:06 +0000 |
| Subject: | Re: [RFC] Reclassifying engine warnings | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106943@lists.php.net to get a copy of this message | ||
Hey Rowan,
<http://ocramius.github.com/>
On Thu, Sep 12, 2019 at 3:30 PM Rowan Tommins <rowan.collins@gmail.com>
wrote:
> For instance, for undefined array keys, what if we had an operator for
> "initialise and retrieve", such as $foo[? 'bar']. Then we could simplify
> ugly code like this:
>
> if ( ! isset($foo[$key1]) {
> $foo[$key1] = [];
> }
> if ( ! isset($foo[$key1][$key2]) {
> $foo[$key1][$key2] = 0;
> }
> $foo[$key1][$key2]++;
>
>
> With something safe but succinct like this:
>
> $foo[? $key1][? $key2]++;
>
$foo[$key1][$key2] = ($foo[$key1][$key2] ?? 0) + 1;
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/