On Thu, 12 Sep 2019 at 11:32, Benjamin Morel <benjamin.mo...@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]

Reply via email to