Jet\Debug_ErrorHandler_Error

Whether ErrorHandler catches an error or an uncaught exception, it always transforms it into an instance of this class and then handles the error.

Each handler expects information in the form of an instance of this class.

Method Overview

Metoda Význam
static newError(
int $code,
string $message,
string $file,
int $line
): static
Creates a instance based on the PHP problem data.
static newException( Throwable $exception ): static Creates a instance by exception
protected static getPHPErrorText(
int $error_number
): string
Functions for internal use. Converts numeric PHP error code to text interpretation.
protected getCurrentURL(): string Function for internal use.

The ErrorHandler itself must be small and as independent as possible from the rest of the system.

This is why it has its own helper function to determine the current URL of the request.
getRequestURL(): string Returns the URL of the request that caused the problem.
getDate(): string Returns the date (YYYY-MM-DD format) when the problem occurred.
getTime(): string Returns the time (format HH:MM:SS) when the problem occurred.
getCode(): int Returns an error code. This is the PHP error code, or the exception code (if the exception had one).
getTxt(): string Returns basic textual information about the problem.
getMessage(): string Returns detailed information about the problem.
getFile(): string The path to the file/script where the problem occurred.
getLine(): int Number of the line where the problem occurred.
getException(): Throwable|null If the problem is an exception, it is possible to get its instance using this method.
getBacktrace(): Debug_ErrorHandler_Error_BacktraceItem[] Returns backtrace to the problem. That is, an array containing an instance of Jet\Debug_ErrorHandler_BacktraceItem
isFatal(): bool Indicates whether this is a fatal problem.
isSilenced(): bool Does it indicate whether this is a benign warning that has been "silenced"? See ErrorHandler
setIsSilenced(
bool $is_silenced
): void
Set the "is silenced" flag. See previous method and also ErrorHandler
__toString(): string
toString(): string
Converts the problem to its text description - to text form without formatting.
Useful especially for logging, or CLI mode, or logging
static setFormatter(
callable $formatter
): void
The class has methods toString() and __toString(). So an error can be easily converted to text. This is used, for example, by a handler that records errors in the log.
You may not be comfortable with the form of these text messages, however. How to solve it? Rebuild the Jet library? Definitely not! Or use inheritance - which would make this part of the system, which by definition should be as simple as possible, very complicated? Also no ...

You can just make your own formatter and set that in initialize ErrorHandler. For example, like this:
Debug_ErrorHandler_Error::setFormatter
    function( 
Debug_ErrorHandler_Error $error ) : string {
        
// ... yours formatter code ...
        
return $txt;
    } 
);
Previous chapter
Jet\Debug_ErrorHandler
Next chapter
Jet\Debug_ErrorHandler_Error_BacktraceItem