| 1 |
[![Latest Stable Version]](https://packagist.org/packages/wikimedia/at-ease) [![License]](https://packagist.org/packages/wikimedia/at-ease) |
| 2 |
|
| 3 |
at-ease |
| 4 |
======= |
| 5 |
|
| 6 |
at-ease is a PHP library that provides a safe alternative to PHP's |
| 7 |
[@ error control operator][]. |
| 8 |
|
| 9 |
`@` is broken when `E_STRICT` is enabled and it causes an unlogged, |
| 10 |
unexplained error if there is a fatal, which is hard to support. The proper |
| 11 |
method of handling errors is to actually handle the errors. For example, if |
| 12 |
you are thinking of using an error suppression operator to suppress an invalid |
| 13 |
array index warning, you should instead perform an `isset()` check on the |
| 14 |
array index before trying to access it. When possible, always prevent PHP |
| 15 |
errors rather than catching and handling them afterward. It makes the code |
| 16 |
more understandable and avoids dealing with slow error suppression methods. |
| 17 |
|
| 18 |
However, there are some cases where warnings are inevitable, even if you check |
| 19 |
beforehand, like when accessing files. You can check that the file exists by |
| 20 |
using `file_exists()` and `is_readable()`, but the file could have been |
| 21 |
deleted by the time you go to read it. In that case, you can use this library |
| 22 |
to suppress the warnings and prevent PHP from being noisy. |
| 23 |
|
| 24 |
|
| 25 |
Usage |
| 26 |
----- |
| 27 |
|
| 28 |
```php |
| 29 |
use Wikimedia\AtEase\AtEase; |
| 30 |
|
| 31 |
// Suppress warnings in a block of code: |
| 32 |
AtEase::suppressWarnings(); |
| 33 |
$content = file_get_contents( 'foobar.txt' ); |
| 34 |
AtEase::restoreWarnings(); |
| 35 |
|
| 36 |
|
| 37 |
// ..or in a callback function: |
| 38 |
AtEase::quietCall( 'file_get_contents', 'foobar.txt' ); |
| 39 |
``` |
| 40 |
|
| 41 |
Running tests |
| 42 |
------------- |
| 43 |
|
| 44 |
composer install --prefer-dist |
| 45 |
composer test |
| 46 |
|
| 47 |
|
| 48 |
History |
| 49 |
------- |
| 50 |
|
| 51 |
This library was first introduced in [MediaWiki 1.3][] ([r4261][]). It was |
| 52 |
split out of the MediaWiki codebase and published as an independent library |
| 53 |
during the [MediaWiki 1.26][] development cycle. |
| 54 |
|
| 55 |
|
| 56 |
--- |
| 57 |
[@ error control operator]: https://php.net/manual/en/language.operators.errorcontrol.php |
| 58 |
[MediaWiki 1.3]: https://www.mediawiki.org/wiki/MediaWiki_1.3 |
| 59 |
[r4261]: https://phabricator.wikimedia.org/rSVN4261 |
| 60 |
[MediaWiki 1.26]: https://www.mediawiki.org/wiki/MediaWiki_1.26 |
| 61 |
[Latest Stable Version]: https://poser.pugx.org/wikimedia/at-ease/v/stable.svg |
| 62 |
[License]: https://poser.pugx.org/wikimedia/at-ease/license.svg |