Jet\Debug_ErrorHandler

Basic class for handlers - modules for error management. Its main purpose is to keep a list of registered handlers, catch PHP errors and catch uncaught exceptions (and other things - vision method list). It is the centerpiece of the ErrorHandler subsystem.

Method Meaning
static registerHandler(
Debug_ErrorHandler $handler
): void
Registers a handler (an instance of a class that inherits from the abstract class Jet\Debug_ErrorHandler_Handler)

WARNING! This method is not used in practice during initialization. Hadler has a static register() method that takes care of the handler registration.
static unRegisterHandler(
string $name
): void
Registers the error handler.
static getHandler(
string $name
): Debug_ErrorHandler_Handler|null
Returns the handler instance by its name - if registered. If it is not, then it returns null.
static getRegisteredHandlers(): Debug_ErrorHandler_Handler[] Returns a list of all registered handlers.
initialize(): void Subsystem initialization.
static handleError(
int $code,
string $message,
string $file = '',
int $line = 0
): void
Catches PHP errors.
static handleException(
Throwable $exception
): void
The method takes care of catching uncaught exceptions.
static getLastError(): Debug_ErrorHandler_Error|null Returns the instance of the last recorded hint.
static addIgnoreNonFatalErrorsPath(
string $path
): void
Sometimes it is necessary to suppress minor error messages like notice, warning and so on. So in general it is not a good idea, every problem should be given due care. This is also why Jet has error reporting fully enabled by default.
But the world is not a perfect place :-) Sometimes you don't have any other option (e.g. when integrating a third party library/component). Then there is the fact that the silence operator (@) cannot be reliably and always detected correctly in PHP8.
Therefore there is an option to set the ErrorHandler to ignore non-serious errors (warning, notice) in certain directories.

What is this good for?

Two situations:
  • Jet has a I/O system where classic file and directory operations are encapsulated so that exceptions are used instead of various warnings. However, it is necessary to somehow suppress the handling of common errors within this part of Jet.
  • The other option is from life. I have had to incorporate a third party library into the system several times. E.g. various clients for third party services, this mainly applies to e-shops. And such a library can be full of different warnings and notices.
    The client (the customer who pays for our services) has no reason to pay for the development of his own library, and nobody will pay the mortgage for you (i.e. we can't work for free). Understandably, our customer/client is interested in making it work and fulfilling its purpose as soon as possible. And if the only problem with the library is that it throws a notice here and there, the best solution is to simply suppress this, but keep full error reporting for your application. (Of course, I won't integrate something that is as leaky as an old necky into the application - I don't encourage you to do anything like that.)
  • ... and you can probably think of something else ...
In a situation like this, it's possible to tell ErrorHandler that there's something potentially slightly problematic here and there and not to pay attention to it.

That's what this static method is for, and you can register directories as you like and need. It just might not be a good idea to register the entire application directory, for example :-)
static getIgnoreNonFatalErrorsPaths(
) : array
See addIgnoreNonFatalErrorsPath.

Returns a list of registered directories.
static doItSilent (
callable $operation
) : array
Again, the issue of error message suppression. It may happen that several factors will work against each other. Jet application should be set up to display/log every error - even a simple warning. On the other hand, some PHP functions may still generate warnings. Of course, we need to use them even when they do generate warnings, but we certainly don't want to log these expected warnings, much less display them.

Unfortunately, the silent operator (@) cannot be detected in PHP8 as it was possible before. Thus, it is not possible to use it effectively even though it would be really useful.

The solution is to do it like this: $cached_data Debug_ErrorHandler::doItSilent(function() use ($cached_data) {
    return 
unserialize$cached_data );
});
Previous chapter
Jet\Debug
Next chapter
Jet\Debug_ErrorHandler_Error