Advertisement
Guest User

Untitled

a guest
May 4th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This code demonstrates how to setup your application
  5. * to intelligently handle errors of all types.
  6. */
  7. ini_set('display_errors', 'Off');
  8. error_reporting(0);
  9.  
  10. /**
  11. * Do something useful like log the error and send back a response.
  12. * This is the global application error handler.
  13. */
  14. function handleErrors()
  15. {
  16. echo 'something bad happened';
  17. exit;
  18. }
  19.  
  20. /**
  21. * This captures all uncaught exceptions.
  22. */
  23. set_exception_handler('handleErrors');
  24.  
  25. /**
  26. * Capture vanilla PHP errors and just convert them to exceptions
  27. */
  28. set_error_handler('handleErrors');
  29.  
  30.  
  31. /**
  32. * The following is required to actually handle E_ERROR type errors
  33. */
  34. register_shutdown_function(function () {
  35. $error = error_get_last();
  36. if (!is_null($error)) {
  37. handleErrors();
  38. }
  39. });
  40.  
  41. // ======================================================================================================
  42.  
  43. /**
  44. * Application code examples
  45. */
  46.  
  47. // this should just hit the set_exception_handler() handler directly.
  48. throw new Exception;
  49.  
  50. /**
  51. * This will cause an E_DEPRECATED to be raised. Sent to set_error_handler()
  52. */
  53. ereg();
  54.  
  55. /**
  56. * This will cause an E_ERROR to be raised. For some reason PHP's set_error_handler()
  57. * won't handle these. Rather you register a register_shutdown_function()
  58. * and get the last error, if one exists then handle the error.
  59. */
  60. some_fake_function_name();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement