2017 © Pedro Peláez
 

library at-ease

Safe replacement to @ for suppressing warnings.

image

wikimedia/at-ease

Safe replacement to @ for suppressing warnings.

  • Saturday, July 28, 2018
  • by mediawiki
  • Repository
  • 17 Watchers
  • 1 Stars
  • 11,520 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 141 % Grown

The README.md

![Latest Stable Version] ![License], (*1)

at-ease

at-ease is a PHP library that provides a safe alternative to PHP's @ error control operator., (*2)

@ 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., (*3)

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., (*4)

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., (*5)


The Versions

28/07 2018
30/12 2017

v1.2.0

1.2.0.0 https://www.mediawiki.org/wiki/at-ease

Safe replacement to @ for suppressing warnings.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.9

 

The Development Requires

by Tim Starling
by MediaWiki developers

18/09 2015

v1.1.0

1.1.0.0 https://www.mediawiki.org/wiki/at-ease

Safe replacement to @ for suppressing warnings.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Tim Starling
by MediaWiki developers

10/06 2015

v1.0.0

1.0.0.0 https://www.mediawiki.org/wiki/at-ease

Safe replacement to @ for suppressing warnings.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Tim Starling
by MediaWiki developers