Re: Deprecation of the Error Control Operator (@ symbol)
| From: | Stanislav Malyshev | Date: | Fri, 08 Jan 2016 18:21:07 +0000 |
| Subject: | Re: Deprecation of the Error Control Operator (@ symbol) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90382@lists.php.net to get a copy of this message | ||
Hi!
> $counts[$item] ?? $counts[$item] = 1 ?? $counts[$item]++;
This looks completely unreadable and I do not think it works:
https://3v4l.org/PlAHH
Seems to leave $counts as 1 always. But even if it didn't, I would never
pass that on code review - it is very hard to understand what's going on
and it is incredibly easy to break it. Doing such stuff is definitely
not the solution, if you hate @, then if() is way better, at least it's
clear.
> $item = new StdClass;
> @$counts[$item] = "This is a bad use of error suppression.";
>
> There is no insertion, because arrays don't support object keys. The
> operation completly failed and so there should be an exception.
No, there should not. If somebody tries to count garbage, I just don't
want to count it. I don't care about it, it's garbage.
> Currently that code fails silently.
And that is exactly what I want it to do. Sometimes silent failure is
*good*, I don't want to know about every little thing that could go
wrong, I just want what's right to be done.
Of course, your intent may be the opposite - but that's exactly the
point, there's more than one use case.
--
Stas Malyshev
smalyshev@gmail.com