class ErrorHandler

handling errors

Properties

protected Error[] $errors holds errors to be displayed or reported later .
protected $hide_location Hide location of errors
protected $error_reporting Initial error reporting state

Methods

__construct()

Constructor - set PHP error handler

__destruct()

Destructor

void
setHideLocation(bool $hide)

Toggles location hiding

array
getErrors(bool $check = true)

returns array with all errors

array
getCurrentErrors()

returns the errors occurred in the current run only.

array
sliceErrors(int $count)

Pops recent errors from the storage

void
handleError(int $errno, string $errstr, string $errfile, int $errline)

Error handler - called when errors are triggered/occurred

void
addError(string $errstr, int $errno, string $errfile, int $errline, bool $escape = true)

Add an error; can also be called directly (with or without escaping)

void
triggerError(string $errorInfo, int|null $errorNumber = null)

trigger a custom error

void
dispFatalError(Error $error)

display fatal error and exit

void
dispUserErrors()

Displays user errors not displayed

string
getDispUserErrors()

Renders user errors not displayed

void
dispPageStart(Error|null $error = null)

display HTML header

void
dispPageEnd()

display HTML footer

string
getDispErrors()

renders errors not displayed

void
checkSavedErrors()

look in session for saved errors

int
countErrors(bool $check = true)

return count of errors

int
countUserErrors()

return count of user errors

bool
hasUserErrors()

whether use errors occurred or not

bool
hasErrors()

whether errors occurred or not

int
countDisplayErrors()

number of errors to be displayed

bool
hasDisplayErrors()

whether there are errors to display or not

void
savePreviousErrors()

Deletes previously stored errors in SESSION.

bool
hasErrorsForPrompt()

Function to check if there are any errors to be prompted.

void
reportErrors()

Function to report all the collected php errors.

Details

at line 43
__construct()

Constructor - set PHP error handler

at line 63
__destruct()

Destructor

stores errors in session

at line 99
void setHideLocation(bool $hide)

Toggles location hiding

Parameters

bool $hide Whether to hide

Return Value

void

at line 111
array getErrors(bool $check = true)

returns array with all errors

Parameters

bool $check Whether to check for session errors

Return Value

array

at line 125
array getCurrentErrors()

returns the errors occurred in the current run only.

Does not include the errors saved in the SESSION

Return Value

array

at line 137
array sliceErrors(int $count)

Pops recent errors from the storage

Parameters

int $count Old error count

Return Value

array

at line 157
void handleError(int $errno, string $errstr, string $errfile, int $errline)

Error handler - called when errors are triggered/occurred

This calls the addError() function, escaping the error string Ignores the errors wherever Error Control Operator (@) is used.

Parameters

int $errno error number
string $errstr error string
string $errfile error file
int $errline error line

Return Value

void

at line 195
void addError(string $errstr, int $errno, string $errfile, int $errline, bool $escape = true)

Add an error; can also be called directly (with or without escaping)

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

Do not use the context parameter as we want to avoid storing the complete $GLOBALS inside $_SESSION['errors']

Parameters

string $errstr error string
int $errno error number
string $errfile error file
int $errline error line
bool $escape whether to escape the error string

Return Value

void

at line 253
void triggerError(string $errorInfo, int|null $errorNumber = null)

trigger a custom error

Parameters

string $errorInfo error message
int|null $errorNumber error number

Return Value

void

at line 267
protected void dispFatalError(Error $error)

display fatal error and exit

Parameters

Error $error the error

Return Value

void

at line 282
void dispUserErrors()

Displays user errors not displayed

Return Value

void

at line 292
string getDispUserErrors()

Renders user errors not displayed

Return Value

string

at line 310
protected void dispPageStart(Error|null $error = null)

display HTML header

Parameters

Error|null $error the error

Return Value

void

at line 327
protected void dispPageEnd()

display HTML footer

Return Value

void

at line 337
string getDispErrors()

renders errors not displayed

Return Value

string

at line 396
protected void checkSavedErrors()

look in session for saved errors

Return Value

void

at line 419
int countErrors(bool $check = true)

return count of errors

Parameters

bool $check Whether to check for session errors

Return Value

int number of errors occurred

at line 429
int countUserErrors()

return count of user errors

Return Value

int number of user errors occurred

at line 448
bool hasUserErrors()

whether use errors occurred or not

Return Value

bool

at line 458
bool hasErrors()

whether errors occurred or not

Return Value

bool

at line 468
int countDisplayErrors()

number of errors to be displayed

Return Value

int number of errors to be displayed

at line 482
bool hasDisplayErrors()

whether there are errors to display or not

Return Value

bool

at line 494
void savePreviousErrors()

Deletes previously stored errors in SESSION.

Saves current errors in session as previous errors. Required to save current errors in case 'ask'

Return Value

void

at line 509
bool hasErrorsForPrompt()

Function to check if there are any errors to be prompted.

Needed because user warnings raised are also collected by global error handler. This distinguishes between the actual errors and user errors raised to warn user.

Return Value

bool true if there are errors to be "prompted", false otherwise

at line 524
void reportErrors()

Function to report all the collected php errors.

Must be called at the end of each script by the $GLOBALS['error_handler'] only.

Return Value

void