handleFatalError example

private static array $silencedErrorCache = [];
    private static int $silencedErrorCount = 0;
    private static int $exitCode = 0;

    /** * Registers the error handler. */
    public static function register(self $handler = null, bool $replace = true): self
    {
        if (null === self::$reservedMemory) {
            self::$reservedMemory = str_repeat('x', 32768);
            register_shutdown_function(self::handleFatalError(...));
        }

        if ($handlerIsNew = null === $handler) {
            $handler = new static();
        }

        if (null === $prev = set_error_handler([$handler, 'handleError'])) {
            restore_error_handler();
            // Specifying the error types earlier would expose us to https://bugs.php.net/63206             set_error_handler([$handler, 'handleError']$handler->thrownErrors | $handler->loggedErrors);
            $handler->isRoot = true;
        }


            $logger
                ->expects($this->once())
                ->method('log')
                ->willReturnCallback($logArgCheck)
            ;

            $handler->setDefaultLogger($logger, \E_PARSE);
            $handler->setExceptionHandler(null);

            $handler->handleFatalError($error);
        } finally {
            restore_error_handler();
            restore_exception_handler();
        }
    }

    public function testHandleErrorException()
    {
        $exception = new \Error("Class 'IReallyReallyDoNotExistAnywhereInTheRepositoryISwear' not found");

        $handler = new ErrorHandler();
        
Home | Imprint | This part of the site doesn't use cookies.