I am learning PHP PDO from a book and I have had to create a file error_handler.php
I understand half it up until the static Handler function sets the variable $backtrace = GetBackTrace(2); ( line 21 ).
It looks like it takes the (2) as an argument which maybe means its working with the 3rd entry of the debug_backtrace array?? eg debug_array(2)??? I’m not sure what that is… I was thinking that it could be the ErrorHandler::SetHandler function as and array but if it is I can’t work out anything further.
Could someone please please please explain what is happening in the Get Back Trace function, i’m going crazy looking at. Broken down for the ultra beginner would be much appreciated.
<?php class ErrorHandler { // Private constructor to prevent direct creation of object private function __construct() { } /* Set user error-handler method to ErrorHandler::Handler method */ public static function SetHandler($errTypes = ERROR_TYPES) { return set_error_handler(array ('ErrorHandler', 'Handler'), $errTypes); } // Error handler method public static function Handler($errNo, $errStr, $errFile, $errLine) { /* The first two elements of the backtrace array are irrelevant: - ErrorHandler.GetBacktrace - ErrorHandler.Handler */ $backtrace = ErrorHandler::GetBackTrace(2); // Error message to be displayed, logged, or mailed $error_message = "\nERRNO: $errNo\nTEXT: $errStr" . "\nLOCATION: $errFile, line " . "$errLine, at " . date('F j, Y, g:i a') . "\nShowing backtrace:\n$backtrace\n\n"; // Email the error details, in case SEND_ERROR_MAIL is true if (SEND_ERROR_MAIL == true) error_log($error_message, 1, ADMIN_ERROR_MAIL, "From: " . SENDMAIL_FROM . "\r\nTo: " . ADMIN_ERROR_MAIL); // Log the error, in case LOG_ERRORS is true if (LOG_ERRORS == true) error_log($error_message, 3, LOG_ERRORS_FILE); /* Warnings don't abort execution if IS_WARNING_FATAL is false E_NOTICE and E_USER_NOTICE errors don't abort execution */ if (($errNo == E_WARNING && IS_WARNING_FATAL == false) || ($errNo == E_NOTICE || $errNo == E_USER_NOTICE)) // If the error is nonfatal ... { // Show message only if DEBUGGING is true if (DEBUGGING == true) echo '' . $error_message . '
'. $error_message . '