Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wikimedia/at-ease
Safe alternative to PHP's "@" error control operator. Mirror from https://gerrit.wikimedia.org/g/at-ease. See https://www.mediawiki.org/wiki/Developer_access for contributing.
https://github.com/wikimedia/at-ease
Last synced: 5 days ago
JSON representation
Safe alternative to PHP's "@" error control operator. Mirror from https://gerrit.wikimedia.org/g/at-ease. See https://www.mediawiki.org/wiki/Developer_access for contributing.
- Host: GitHub
- URL: https://github.com/wikimedia/at-ease
- Owner: wikimedia
- License: gpl-2.0
- Created: 2015-06-06T20:35:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-12T05:49:39.000Z (9 days ago)
- Last Synced: 2024-12-12T06:29:15.865Z (9 days ago)
- Language: PHP
- Homepage: https://www.mediawiki.org/wiki/At-ease
- Size: 89.8 KB
- Stars: 13
- Watchers: 15
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: COPYING
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome - wikimedia/at-ease - Safe alternative to PHP's "@" error control operator. Mirror from https://gerrit.wikimedia.org/g/at-ease. See https://www.mediawiki.org/wiki/Developer\_access for contributing. (PHP)
README
[![Latest Stable Version]](https://packagist.org/packages/wikimedia/at-ease) [![License]](https://packagist.org/packages/wikimedia/at-ease)
at-ease
=======at-ease is a PHP library that provides a safe alternative to PHP's
[@ error control operator][].`@` is broken when `E_STRICT` is enabled and it causes an unlogged,
unexplained error if there is a fatal, which is hard to support. The proper
method of handling errors is to actually handle the errors. For example, if
you are thinking of using an error suppression operator to suppress an invalid
array index warning, you should instead perform an `isset()` check on the
array index before trying to access it. When possible, always prevent PHP
errors rather than catching and handling them afterward. It makes the code
more understandable and avoids dealing with slow error suppression methods.However, there are some cases where warnings are inevitable, even if you check
beforehand, like when accessing files. You can check that the file exists by
using `file_exists()` and `is_readable()`, but the file could have been
deleted by the time you go to read it. In that case, you can use this library
to suppress the warnings and prevent PHP from being noisy.Usage
-----```php
use Wikimedia\AtEase\AtEase;// Suppress warnings in a block of code:
AtEase::suppressWarnings();
$content = file_get_contents( 'foobar.txt' );
AtEase::restoreWarnings();// ..or in a callback function:
AtEase::quietCall( 'file_get_contents', 'foobar.txt' );
```Running tests
-------------composer install --prefer-dist
composer testHistory
-------This library was first introduced in [MediaWiki 1.3][] ([r4261][]). It was
split out of the MediaWiki codebase and published as an independent library
during the [MediaWiki 1.26][] development cycle.---
[@ error control operator]: https://php.net/manual/en/language.operators.errorcontrol.php
[MediaWiki 1.3]: https://www.mediawiki.org/wiki/MediaWiki_1.3
[r4261]: https://phabricator.wikimedia.org/rSVN4261
[MediaWiki 1.26]: https://www.mediawiki.org/wiki/MediaWiki_1.26
[Latest Stable Version]: https://poser.pugx.org/wikimedia/at-ease/v/stable.svg
[License]: https://poser.pugx.org/wikimedia/at-ease/license.svg