On Fri, Jan 8, 2016 at 11:21 AM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> 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.


I agree with Dan on this one. Trying to use an invalid type as a key should
produce something. Your argument that its garbage and you don't care may be
valid for a specific use case, but it may also be a bug in another case.
IE: it wasn't supposed to be an object, and the wrong variable was used,
but tracking down that error if nothing is produced when doing something
defined as invalid will be hard. If you don't want to count garbage, then
you should use if()

if (!is_garbage($key)) @$count[$key]++;


>
> > 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
> smalys...@gmail.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to