title: Redirect to error page in onBootstrap when a fatal error is encountered
body: <p>I am trying to redirect a user to an error page upon encountering a FATAL error. I wanted to do this redirect in onBootstrap method, like this.</p>
  
  <pre><code>&lt;?php
  use Zend\Mvc\MvcEvent;
  
  class Module
  {
      public function onBootstrap(MvcEvent $e)
      {
          $eventManager   = $e-&gt;getApplication()-&gt;getEventManager();
          $serviceManager = $e-&gt;getApplication()-&gt;getServiceManager();
  
          register_shutdown_function(function (MvcEvent $event)
          {
              $response = $event-&gt;getResponse();
              $response-&gt;setHeaders(
                  $response-&gt;getHeaders()-&gt;addHeaderLine('Location', "/error-page")
              );
              $response-&gt;setStatusCode(302);
              $response-&gt;sendHeaders();
              return $response;
          });     
      }
  }
  ?&gt;
  </code></pre>
  
  <p>However, I am getting an error saying:</p>
  
  <pre><code>    Catchable fatal error: Argument 1 passed to 
  MyException\Module::MyException\{closure}() must be an instance of 
  Zend\Mvc\MvcEvent, none given in MyException\Module.php on line 11.
  </code></pre>
  
  <p>Is there any other way to redirect the user?</p>
  
  <p>I tried this as well, but I am getting <strong>headers are already sent</strong> error.</p>
  
  <pre><code>register_shutdown_function(function ()
          {
              ob_clean();
              ob_flush();
              ob_start();
              header ('Location: /');
              ob_end();
          });
  </code></pre>
  
  <p>Any Ideas on how to fix this?</p>
  
  <p>Thanks,</p>