1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- ini_set('display_errors', false);
- // set to the user defined error handler
- set_error_handler(function($errno, $errstr, $errfile, $errline) {
- if (!(error_reporting() & $errno)) {
- // This error code is not included in error_reporting, so let it fall
- // through to the standard PHP error handler
- return false;
- }
- switch ($errno) {
- case E_USER_ERROR:
- echo <<<ERROR
- <article class="message is-danger">
- <div class="message-body">
- <strong>Error!!!</strong><br />\n
- $errstr<br />\n
- Fatal error on line $errline in file $errfile<br />\n
- Aborting...<br />\n
- </div>
- </article>
- ERROR;
- exit(1);
- break;
- case E_USER_WARNING:
- echo <<<WARNING
- <article class="message is-warning">
- <div class="message-body">
- <strong>Warning!!!</strong><br />\n
- $errstr<br />\n
- Warning on line $errline in file $errfile<br />\n
- </div>
- </article>
- WARNING;
- break;
- case E_USER_NOTICE:
- echo <<<NOTICE
- <article class="message is-dark">
- <div class="message-body">
- <strong>Notice!!!</strong><br />\n
- $errstr<br />\n
- Notice on line $errline in file $errfile<br />\n
- </div>
- </article>
- NOTICE;
- break;
- default:
- echo "Unknown error type: [$errno] $errstr<br />\n";
- break;
- }
- /* Don't execute PHP internal error handler */
- return true;
- });
- function shutdown()
- {
- // This is our shutdown function, in
- // here we can do any last operations
- // before the script is complete.
- echo 'Script executed with success', PHP_EOL;
- }
- register_shutdown_function(function() {
- $error = error_get_last();
- switch ($error['type']) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_CORE_WARNING:
- case E_PARSE:
- echo <<<ERROR
- <article class="message is-danger">
- <div class="message-body">
- <strong>Error!!!</strong><br />\n
- {$error['message']}<br />\n
- PHP Internal error on line {$error['line']} in file {$error['file']}<br />\n
- Aborting...<br />\n
- </div>
- </article>
- ERROR;
- break;
- default:
- if (!empty($error['type'])) {
- echo "Unknown error type: {$error['type']} {$error['message']}<br />\n";
- }
- }
- return true;
- });
|