A safe alternative to PHP's "@" error control operator.
Switch branches/tags
Clone or download
libraryupgrader
libraryupgrader build: Updating mediawiki/mediawiki-codesniffer to 23.0.0
Change-Id: I788fbffc7c04455819329aab8d04d04396a71f8e
Latest commit e844d0d Nov 17, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Sync with library bootstrap May 6, 2018
doc Initial commit Jun 10, 2015
src/Wikimedia Use static class methods instead of global functions Apr 20, 2018
tests/Wikimedia Use static class methods instead of global functions Apr 20, 2018
.editorconfig
.gitattributes
.gitignore Sync with library bootstrap May 6, 2018
.gitreview Sync with library bootstrap May 6, 2018
.phpcs.xml Sync with library bootstrap May 6, 2018
.travis.yml build: Stop Travis trying to test pre-7.0.0 PHP Oct 10, 2018
CODE_OF_CONDUCT.md
COPYING Use the plaintext GPL Jun 17, 2016
Doxyfile Sync with library bootstrap May 6, 2018
History.md
README.md
composer.json build: Updating mediawiki/mediawiki-codesniffer to 23.0.0 Nov 17, 2018
phpunit.xml.dist Sync with library bootstrap May 6, 2018

README.md

Latest Stable Version License

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

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 test

History

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.