Best way to handle register_shutdown_function

I have already registered the slim error handlers (below) but they don’t seem to catch when you run out of memory (fatal error), which is why I have a registered shutdown function. Perhaps there is some issue with how I have registerd them.

        $app = SiteSpecific::getSlimApp();
        
        // set the error handlers
        // https://www.slimframework.com/docs/handlers/error.html
        $container = $app->getContainer();
        
        $errorHandler = function($request, $response, $args) {
            return $response->withStatus(500)
                            ->withHeader('Content-Type', 'application/json')
                            ->write('Something went wrong!');
        };
        
        
        // This is returned when the route exists but the method, such as POST or PATCH does
        // not exist for it.
        $methodNotAllowedHandler = function($request, $response, $args) {
            $ex = new Exception("That method is not allowed.", HTTP_METHOD_NOT_ALLOWED);
            return SiteSpecific::getErrorResponseForException($ex, $response);
        };
        
        $container['errorHandler'] = function ($container) use ($errorHandler) {
            return $errorHandler;
        };
        
        // Runtime PHP errors (PHP 7+ only)
        $container['phpErrorHandler'] = function ($container) use ($errorHandler) {
            return $errorHandler;
        };
        
        $container['notAllowedHandler'] = function ($container) use ($methodNotAllowedHandler) {
            return $methodNotAllowedHandler;
        };
        
        $container['notFoundHandler'] = function ($container) {
            // need to use an annonymous class here due to the fact that need to use $container
            // at last possible second.
            return new class($container) {
                private $m_container;
                
                public function __construct($container)
                {
                    $this->m_container = $container;
                }
                
                public function __invoke($request, $response) 
                {
                    $ex = new Exception("That method/route does not exist.", HTTP_NOT_FOUND);
                    return SiteSpecific::getErrorResponseForException($ex, $response);
                }
            };
        };