From 4f055f25ad547e9faf94417dfd58c2082e8e31f1 Mon Sep 17 00:00:00 2001
From: gggeek <giunta.gaetano@gmail.com>
Date: Sat, 30 May 2015 13:48:28 +0200
Subject: [PATCH] Correctly reset php error handler even when user-code raises
 an exception

---
 NEWS           | 5 +++++
 src/Server.php | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/NEWS b/NEWS
index 8d8c130a..5880306c 100644
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,11 @@ PLEASE READ CAREFULLY THE NOTES BELOW to insure a smooth upgrade.
 
 * improved: more tests in the test suite
 
+* fixed: the server would not reset the user-set debug messages between subsequent service() calls
+
+* fixed: the server would not reset previous php error handlers when an exception was thrown by user code and
+  exception_handling set to 2
+
 * fixed: the server would fail to decode a request with ISO-8859-1 payload and character set declaration in the xml
   prolog only
 
diff --git a/src/Server.php b/src/Server.php
index 96aac17c..70b45de3 100644
--- a/src/Server.php
+++ b/src/Server.php
@@ -678,6 +678,13 @@ class Server
             // in the called function, we wrap it in a proper error-response
             switch ($this->exception_handling) {
                 case 2:
+                    if ($this->debug > 2) {
+                        if (self::$_xmlrpcs_prev_ehandler) {
+                            set_error_handler(self::$_xmlrpcs_prev_ehandler);
+                        } else {
+                            restore_error_handler();
+                        }
+                    }
                     throw $e;
                     break;
                 case 1:
-- 
2.47.0