Skip to content

[Debug] Ability to register custom fatal error handlers #27201

@fduch

Description

@fduch

My purpose is to register custom fatal error handler inside my own bundle.

As i initially understood the right way to do it is to override ErrorHandler's getFatalErrorHandlers method.

The entire problem here is that i am not sure about how to replace original error handler with extended one.

My first attempt involved substitution of original error handler inside my bundle's boot method:

class MyBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function boot()
    {
        ErrorHandler::register(new MyErrorHandler($this->container), true)
            ->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
    }
}

But after #15521 was merged this approach became inconsistent with Debug::enable since initial error handler is registered depending on $displayErrors inside Debug::enable and after that it is hardly replaced by custom one (and original one is lost).

So what is the right way to register custom fatal error handler without making all the things by myself (i mean replacing Debug::enable with custom logic that registers custom error handler)?

May be it would be reasonable to add something like addFatalErrorHandler method to ErrorHandler in order to make possible dynamic registration of fatal handlers?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions