Disabling the silence @-operator in PHP

PHP supports one error control operator: the at sign (@). When prepended to an expression any error generated by that expression will be ignored. It can also be useful for hiding errors generated by various functions.Take the following simple example:

$var = $_GET['data'];

If the ‘data’ parameter is not defined the expression will generate an error.

Notice: Undefined index: data in /var/www/test.php on line 9

You can hide the error using the silence @-operator.

$var = @  $_GET['data'];

Although quite useful at some times, using the @-operator can have some annoying side effects. Say you are using some external libraries in your application which uses the @-operator. If everything works fine than good. But if the library is generating some errors than it becomes difficult to point the exact location where the error occurs, as the @-operator hides it. If the external library is large, it becomes a headache to remove all the @ from the code. One nice option I found is the Scream Pecl extension. The extension allows you to easily disable the @-operator in your code without making any actual changes to the code.
(more…)

Read More