You have several options in terms of debugging unknown errors.
- The first method is simple, but it requires a PHP extension.
- The second method offers a more complex practical approach, but is definitely worth it if you are in the low-level internal workings of the PHP interpreter. In addition, you will need to configure linux and PHP with
--enable-debug . - The third and, in my opinion, the easiest way does not require the use of any external programs or added PHP extensions.
ErrorHandler.php:
<?php class ErrorHandler { public static function captureError($err_no, $message, $file, $line) { echo '<strong>Error (#' . $err_no . '):</strong> ' . $message . ' in ' . $file . ' on line #' . $line . '<br />'; debug_print_backtrace(); } public static function captureException($exception) { echo '<pre>' . print_r($exception, true) . '</pre>'; } public static function captureShutdown() { if (($error = error_get_last()) !== null) { debug_print_backtrace(); } } } set_error_handler(array('ErrorHandler', 'captureError')); set_exception_handler(array('ErrorHandler', 'captureException')); register_shutdown_function(array('ErrorHandler', 'captureShutdown')); ?>
source share