/** * Handle a standard PHP error * * @param integer $error_number * @param string $error_string * @param string $error_file * @param integer $error_line * @return void */ public static function handle_error($error_number, $error_string, $error_file, $error_line) { // if a command is called with "@", then we should return if (error_reporting() == 0) { return; } // if we are currently dealing with reporting an error, don't go on if (self::$type) { return; } // setup this error object self::$type = 'Error'; self::$message = $error_string; self::$filename = $error_file; self::$line_number = $error_line; // set object type based on error code switch ($error_number) { case E_ERROR: self::$object_type = 'E_ERROR'; break; case E_WARNING: self::$object_type = 'E_WARNING'; break; case E_PARSE: self::$object_type = 'E_PARSE'; break; case E_NOTICE: self::$object_type = 'E_NOTICE'; break; case E_STRICT: self::$object_type = 'E_STRICT'; break; case E_CORE_ERROR: self::$object_type = 'E_CORE_ERROR'; break; case E_CORE_WARNING: self::$object_type = 'E_CORE_WARNING'; break; case E_COMPILE_ERROR: self::$object_type = 'E_COMPILE_ERROR'; break; case E_COMPILE_WARNING: self::$object_type = 'E_COMPILE_WARNING'; break; case E_USER_ERROR: self::$object_type = 'E_USER_ERROR'; break; case E_USER_WARNING: self::$object_type = 'E_USER_WARNING'; break; case E_USER_NOTICE: self::$object_type = 'E_USER_NOTICE'; break; case E_DEPRECATED: self::$object_type = 'E_DEPRECATED'; break; case E_USER_DEPRECATED: self::$object_type = 'E_USER_DEPRECATED'; break; case E_RECOVERABLE_ERROR: self::$object_type = 'E_RECOVERABLE_ERROR'; break; default: self::$object_type = 'Unknown'; break; } // setup the stack trace self::$stack_trace = ""; // capture back trace $back_trace = debug_backtrace(); // loop entire trace stack for ($index = 0; $index < count($back_trace); $index++) { // current item $item = $back_trace[$index]; // determine keys $key_file = array_key_exists('file', $item) ? $item['file'] : ''; $key_line = array_key_exists('line', $item) ? $item['line'] : ''; $key_class = array_key_exists('class', $item) ? $item['class'] : ''; $key_type = array_key_exists('type', $item) ? $item['type'] : ''; $key_function = array_key_exists('function', $item) ? $item['function'] : ''; // append to stack trace report self::$stack_trace .= sprintf("#%s %s(%s): %s%s%s()\n", $index, $key_file, $key_line, $key_class, $key_type, $key_function); } self::run(); }