]> git.andy128k.dev Git - ipf.git/commitdiff
fix error handler related code
authorAndrey Kutejko <aku@anahoret.com>
Tue, 20 Jan 2015 14:30:51 +0000 (16:30 +0200)
committerAndrey Kutejko <aku@anahoret.com>
Tue, 20 Jan 2015 14:30:51 +0000 (16:30 +0200)
ipf/middleware/error.php

index 28fb3117c8e8142d79d89ed73d8c5765a653619b..436481f5d2b3d9ce3ad14df57deac35aa664eaf5 100644 (file)
@@ -4,7 +4,7 @@ class IPF_Error_Middleware extends IPF_Middleware
 {
     function call($request)
     {
-        $previous = set_error_handler(array($this, 'error_handler'));
+        $this->previous_error_handler = set_error_handler(array($this, 'error_handler'));
         register_shutdown_function(array($this, 'shutdown_handler'), $request);
         try {
             if (!$this->next)
@@ -18,7 +18,10 @@ class IPF_Error_Middleware extends IPF_Middleware
             error_log($exception);
             $response = new IPF_HTTP_Response_ServerError($request, $exception);
         }
-        set_error_handler($previous);
+        if ($this->previous_error_handler)
+            set_error_handler($previous);
+        else
+            restore_error_handler();
         return $response;
     }
 
@@ -26,6 +29,9 @@ class IPF_Error_Middleware extends IPF_Middleware
     {
         if (error_reporting() & $errno)
             throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
+
+        if ($this->previous_error_handler)
+            call_user_func($this->previous_error_handler, $errno, $errstr, $errfile, $errline);
     }
 
     function shutdown_handler($request)