error_clear_last()

Unknown to many developers, PHP provides an API to get the last error that occurred even without the need to mess with the PHP configuration and enable tracking of errors. This is a rather handy feature, given that it can be used in a shutdown function to check if any unhandled errors occurred. It also allows for a controlled shutdown just in case.

register_shutdown_function(
    function() {
        $error = error_get_last();
        if ($error !== null) {
            var_dump($error);
        }
    }
);

The only downside to this approach is that with PHP 5 there was no way to clear the error entry once it got handled. This reduced the usefulness of this feature quite dramatically, at least, when other areas of the code needed to deal with error handling as well.

With PHP 7, the new function error_clear_last() got introduced which fixes that oversight.

@$x = $undefined;
var_dump(error_get_last());

error_clear_last();

var_dump(error_get_last());

If executed, the above example will output an array with details of the suppressed notice for using an undefined variable. After clearing the error, the following call returns null.