Re: [RFC] Reclassifying engine warnings
| From: | Benjamin Morel | Date: | Thu, 12 Sep 2019 14:12:45 +0000 |
| Subject: | Re: [RFC] Reclassifying engine warnings | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106954@lists.php.net to get a copy of this message | ||
>> $foo[$key1][$key2] = ($foo[$key1][$key2] ?? 0) + 1;
> That violates blatantly DRY (twice the exact same lengthy expression
$foo[$key1][$key2]), so it is not a satisfactory solution.
$foo[$key1][$key2]??++ 😃
More seriously, yes as Marco suggested, yes we can already do it, and as
Claude pointed out, yes that's verbose.
What I had in mind with language support is some kind of code-level (per
line or block) switch that would allow uninitialized array keys to behave
in a certain way, *depending on the context* : we actually have not one,
but two good examples of this above, provided that $key1 and $key2 do not
exist:
- with [], an unitialized key would be initialized with an empty array
(already does that)
- with ++, an unitialized key would be initialized with 0
Without the proper code-level switch, we could safely have both cases above
throw an exception.
— Benjamin