On 8 January 2016 at 15:48, Rowan Collins <rowan.coll...@gmail.com> wrote:
>
> It doesn't do anything to help Stas's example for instance:
>
> @$counts[$item]++;

I think that that code is bogus since the release of PHP 7, which made
it trivial to not use the error suppression for this case, while still
writing code that doesn't take up multiple lines.

$counts[$item] ?? $counts[$item] = 1 ?? $counts[$item]++;

Yes - it's a few more characters but it has another benefit:

> This is not something which should ever throw an exception,

Oh yes, it definitely should:

$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.
Currently that code fails silently.

> I think it would be perfectly reasonable to implement a new file handling 
> API, which behaves like
> modern PHP (objects, exceptions, etc) rather than being a thin wrapper for C
>
> I would also contend that a correctly thrown exception should never be
> something you want to just suppress

I very much look forward to seeing your proposal for this file
handling API, which is both easy to use, and never throws exceptions
which people will want to discard.

cheers
Dan

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to