ErrorHandler
in package
SMF's error handler.
Also provides methods for logging and/or dying when errors occur.
Table of Contents
Methods
- __construct() : mixed
- Constructor.
- call() : void
- Convenience method to create an instance of this class.
- displayDbError() : void
- Show an error message for the connection problems.
- displayLoadAvgError() : void
- Show an error message for load average blocking problems.
- displayMaintenanceMessage() : void
- Show a message for the (full block) maintenance mode.
- fatal() : void
- An irrecoverable error.
- fatalLang() : void
- Shows a fatal error with a message stored in the language file.
- log() : string
- Log an error, if the error logging is enabled.
- logLastDatabaseError() : bool
- Logs the last database error into a file.
- logOnline() : void
- Small utility function for fatal error pages.
- setFatalHeaders() : void
- Small utility function for fatal error pages.
- setupFatalContext() : void
- It is called by self::fatal() and self::fatalLang().
Methods
__construct()
Constructor.
public
__construct(int $error_level, string $error_string, string $file, int $line) : mixed
Parameters
call()
Convenience method to create an instance of this class.
public
static call(int $error_level, string $error_string, string $file, int $line) : void
Parameters
displayDbError()
Show an error message for the connection problems.
public
static displayDbError() : void
It shows a complete page independent of language files or themes. It is used only if there's no way to connect to the database. It stops further execution of the script.
Tags
displayLoadAvgError()
Show an error message for load average blocking problems.
public
static displayLoadAvgError() : void
It shows a complete page independent of language files or themes. It is used only if the load averages are too high to continue execution. It stops further execution of the script.
Tags
displayMaintenanceMessage()
Show a message for the (full block) maintenance mode.
public
static displayMaintenanceMessage() : void
It shows a complete page independent of language files or themes. It is used only if $maintenance = 2 in Settings.php. It stops further execution of the script.
Tags
fatal()
An irrecoverable error.
public
static fatal(string $error[, string|bool $log = 'general' ][, int $status = 500 ]) : void
This function stops execution and displays an error message. It logs the error message if $log is specified.
Parameters
- $error : string
-
The error message
- $log : string|bool = 'general'
-
= 'general' What type of error to log this as (false to not log it))
- $status : int = 500
-
The HTTP status code associated with this error
fatalLang()
Shows a fatal error with a message stored in the language file.
public
static fatalLang(string $error[, string|false $log = 'general' ][, array<string|int, mixed> $sprintf = [] ][, int $status = 403 ]) : void
This function stops execution and displays an error message by key.
- uses the string with the error_message_key key.
- logs the error in the forum's default language while displaying the error message in the user's language.
- uses Errors language file and applies the $sprintf information if specified.
- the information is logged if log is specified.
Parameters
- $error : string
-
The error message.
- $log : string|false = 'general'
-
The type of error, or false to not log it.
- $sprintf : array<string|int, mixed> = []
-
An array of data to be substituted into the specified message.
- $status : int = 403
-
The HTTP status code associated with this error. Default: 403.
log()
Log an error, if the error logging is enabled.
public
static log(string $error_message[, string|bool $error_type = 'general' ][, string $file = '' ][, int $line = 0 ]) : string
$file and $line should be FILE and LINE, respectively.
Example use: die(ErrorHandler::log($msg));
Parameters
- $error_message : string
-
The message to log.
- $error_type : string|bool = 'general'
-
The type of error.
- $file : string = ''
-
The name of the file where this error occurred.
- $line : int = 0
-
The line where the error occurred.
Return values
string —The message that was logged.
logLastDatabaseError()
Logs the last database error into a file.
protected
static logLastDatabaseError() : bool
Attempts to use the backup file first, to store the last database error and only update db_last_error.php if the first was successful.
Return values
bool —true if successfully able to write the last database error.
logOnline()
Small utility function for fatal error pages.
protected
static logOnline(string $error[, array<string|int, mixed> $sprintf = [] ]) : void
Used by self::fatal() and self::fatalLang().
Parameters
- $error : string
-
The error
- $sprintf : array<string|int, mixed> = []
setFatalHeaders()
Small utility function for fatal error pages.
protected
static setFatalHeaders() : void
Used by self::displayMaintenanceMessage(), self::displayDbError(), and self::displayLoadAvgError().
setupFatalContext()
It is called by self::fatal() and self::fatalLang().
protected
static setupFatalContext(string $error_message[, string $error_code = null ]) : void
Parameters
- $error_message : string
-
The error message
- $error_code : string = null
-
An error code