class ErrorHandler (View source)

handling errors

Properties

static self|null $instance
protected Error[] $errors

holds errors to be displayed or reported later .

protected bool $hideLocation

Hide location of errors

protected int $errorReporting

Initial error reporting state

Methods

__construct()

No description

static ErrorHandler
getInstance()

No description

__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

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

Error handler - called when errors are triggered/occurred

void
handleException(Throwable $exception)

Hides exception if it's not in the development environment.

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)

never
dispFatalError(Error $error)

display fatal error and exit

void
dispUserErrors()

Displays user errors not displayed

string
getDispUserErrors()

Renders user errors not displayed

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

__construct()

No description

static ErrorHandler getInstance()

No description

Return Value

ErrorHandler

__destruct()

Destructor

stores errors in session

void setHideLocation(bool $hide)

Toggles location hiding

Parameters

bool $hide

Whether to hide

Return Value

void

array getErrors(bool $check = true)

returns array with all errors

Parameters

bool $check

Whether to check for session errors

Return Value

array

array getCurrentErrors()

returns the errors occurred in the current run only.

Does not include the errors saved in the SESSION

Return Value

array

array sliceErrors(int $count)

Pops recent errors from the storage

Parameters

int $count

Old error count (amount of errors to splice)

Return Value

array

The non spliced elements (total-$count)

bool 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

bool

Exceptions

ErrorException

void handleException(Throwable $exception)

Hides exception if it's not in the development environment.

Parameters

Throwable $exception

Return Value

void

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

protected never dispFatalError(Error $error)

display fatal error and exit

Parameters

Error $error

the error

Return Value

never

void dispUserErrors()

Displays user errors not displayed

Return Value

void

string getDispUserErrors()

Renders user errors not displayed

Return Value

string

string getDispErrors()

renders errors not displayed

Return Value

string

protected void checkSavedErrors()

look in session for saved errors

Return Value

void

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

int countUserErrors()

return count of user errors

Return Value

int

number of user errors occurred

bool hasUserErrors()

whether use errors occurred or not

Return Value

bool

bool hasErrors()

whether errors occurred or not

Return Value

bool

int countDisplayErrors()

number of errors to be displayed

Return Value

int

number of errors to be displayed

bool hasDisplayErrors()

whether there are errors to display or not

Return Value

bool

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

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

void reportErrors()

Function to report all the collected php errors.

Must be called at the end of each script by the {\PhpMyAdmin\Error\getInstance()} only.

Return Value

void