-
Notifications
You must be signed in to change notification settings - Fork 151
Functions are provided for common case code.
This is the most common usage scenario. Call 'reportErrors()', and you get stricter error reporting, and pretty HTML errors. Displaying errors in ajax also works by default.
\php_error\reportErrors();
Optionally you can pass in an array of options, see the Options section for more details.
Internally it will create a new \php_error\ErrorHandler, turn it on, and then return it.
$handler = \php_error\reportErrors();
So you can grab that to allow you to allow you to alter the error handling manually.
This will turn off errors, and then run the callback given, and then turn error reporting back on. That is useful if you have a block of code which you know will thrown an error, such as loading a third party library/framework, such as Wordpress.
withoutErrors( function() {
// run buggy code here
} );
The result from calling the callback is returned.
There is also an ErrorHandler class to allow you greater control over the error reporting.
Just like 'reportErrors', the ErrorHandler can optionally take an array of options you can set. See the 'options' section on what these are, and what they do.
$handler = new \php_error\ErrorHandler()
$handler = new \php_error\ErrorHandler( array(
// set options here
) );
The ErrorHandler will not be on by default, unlike with 'reportErrors'. You need to explicitely turn it on yourself.
Returns 'true' if error reporting using the handler is on, false if not.
Return 'false' if the error handler is on, and true if it is off.
If error reporting is currently off, then it will now be turned on.
This error handler is returned.
If error reporting is off, then it is now turned on.
This error handler is returned.
Works just like the function withoutErrors; that actually just calls into this function.
It turns off error reporting (if it is on), then runs the callback given, and then turns error reporting back on (if it was on).
$handler->withoutErrors( function() {
// run buggy code here
} );
The result from calling the callback is returned.
If this is already off, then it'll just call it, and return the result.