Re: [RFC] Reclassifying engine warnings
| From: | Rowan Tommins | Date: | Thu, 12 Sep 2019 13:29:51 +0000 |
| Subject: | Re: [RFC] Reclassifying engine warnings | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106942@lists.php.net to get a copy of this message | ||
On Thu, 12 Sep 2019 at 11:32, Benjamin Morel <benjamin.morel@gmail.com>
wrote:
> I don't think there are that many such *potentially *legitimate use cases,
> so maybe we could just list the use cases and think about a more elegant
> solution to solve them?
>
Yes, please. If we can focus less on vague anecdotes and opinions *on both
sides*, we can look at *making the language more pleasant to use*.
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]++;
Unlike the error suppression @ operator, this is not saying "I know I'm
doing something wrong, do it anyway"; it's saying "I want to do this
specific thing, I just want to do it in fewer lines of code".
The more helpers like this we have, the more I'd be amenable to
*eventually* raising things to Error - although I still think that should
be done over a longer period of time than a single release cycle.
Regards,
--
Rowan Tommins
[IMSoP]