Last active
August 29, 2015 14:28
-
-
Save fer-ri/ff7e6ec269833deaf975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This code demonstrates how to setup your application | |
| * to intelligently handle errors of all types. | |
| */ | |
| ini_set('display_errors', 'Off'); | |
| error_reporting(0); | |
| /** | |
| * Do something useful like log the error and send back a response. | |
| * This is the global application error handler. | |
| */ | |
| function handleErrors() | |
| { | |
| echo 'something bad happened'; | |
| exit; | |
| } | |
| /** | |
| * This captures all uncaught exceptions. | |
| */ | |
| set_exception_handler('handleErrors'); | |
| /** | |
| * Capture vanilla PHP errors and just convert them to exceptions | |
| */ | |
| set_error_handler('handleErrors'); | |
| /** | |
| * The following is required to actually handle E_ERROR type errors | |
| */ | |
| register_shutdown_function(function () { | |
| $error = error_get_last(); | |
| if (!is_null($error)) { | |
| handleErrors(); | |
| } | |
| }); | |
| // ====================================================================================================== | |
| /** | |
| * Application code examples | |
| */ | |
| // this should just hit the set_exception_handler() handler directly. | |
| throw new Exception; | |
| /** | |
| * This will cause an E_DEPRECATED to be raised. Sent to set_error_handler() | |
| */ | |
| ereg(); | |
| /** | |
| * This will cause an E_ERROR to be raised. For some reason PHP's set_error_handler() | |
| * won't handle these. Rather you register a register_shutdown_function() | |
| * and get the last error, if one exists then handle the error. | |
| */ | |
| some_fake_function_name(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment