From: gggeek Date: Sun, 26 Feb 2023 21:38:44 +0000 (+0000) Subject: make server swallow php warnings when not in debug mode X-Git-Tag: 4.10.2~6 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3714098f806d75b383e933d5052548ef72d0cf97;p=plcapi.git make server swallow php warnings when not in debug mode --- diff --git a/NEWS.md b/NEWS.md index ea229922..0e7b7971 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +## XML-RPC for PHP version 4.XX - unreleased + +* fixed: allow `Server` subclasses to use their own Parser to determine the Request's charset + +* fixed: the Server would not swallow and log php warnings generated from end user's method handler functions unless + debug mode was set to 2 or higher. It now does that always. + + ## XML-RPC for PHP version 4.10.1 - 2023/02/22 * fixed: class autoloading got broken in rel 4.10.0 for users of the legacy API (issue #111) diff --git a/demo/server/server.php b/demo/server/server.php index 893bf9e5..9c764615 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -61,6 +61,9 @@ $s->setOption(Server::OPT_DEBUG, 3); // Out-of-band information: let the client manipulate the server operations. // We do this to help the testsuite script: *** do not reproduce in production or public environments! *** if (defined('TESTMODE')) { + if (isset($_GET['FORCE_DEBUG'])) { + $s->setOption(Server::OPT_DEBUG, $_GET['FORCE_DEBUG']); + } if (isset($_GET['RESPONSE_ENCODING'])) { $s->setOption(Server::OPT_RESPONSE_CHARSET_ENCODING, $_GET['RESPONSE_ENCODING']); } diff --git a/src/Server.php b/src/Server.php index 8c24d5eb..b583a60d 100644 --- a/src/Server.php +++ b/src/Server.php @@ -847,11 +847,11 @@ class Server $exception_handling = $this->exception_handling; } - // If debug level is 3, we should catch all errors generated during processing of user function, and log them - // as part of response - if ($this->debug > 2) { - self::$_xmlrpcs_prev_ehandler = set_error_handler(array('\PhpXmlRpc\Server', '_xmlrpcs_errorHandler')); - } + // We always catch all errors generated during processing of user function, and log them as part of response; + // if debug level is 3 or above, we also serialize them in the response as comments + self::$_xmlrpcs_prev_ehandler = set_error_handler(array('\PhpXmlRpc\Server', '_xmlrpcs_errorHandler')); + + /// @todo what about using output-buffering as well, in case user code echoes anything to screen? try { // Allow mixed-convention servers @@ -910,12 +910,11 @@ class Server // proper error-response switch ($exception_handling) { case 2: - if ($this->debug > 2) { - if (self::$_xmlrpcs_prev_ehandler) { - set_error_handler(self::$_xmlrpcs_prev_ehandler); - } else { - restore_error_handler(); - } + if (self::$_xmlrpcs_prev_ehandler) { + set_error_handler(self::$_xmlrpcs_prev_ehandler); + self::$_xmlrpcs_prev_ehandler = null; + } else { + restore_error_handler(); } throw $e; case 1: @@ -933,12 +932,11 @@ class Server // proper error-response switch ($exception_handling) { case 2: - if ($this->debug > 2) { - if (self::$_xmlrpcs_prev_ehandler) { - set_error_handler(self::$_xmlrpcs_prev_ehandler); - } else { - restore_error_handler(); - } + if (self::$_xmlrpcs_prev_ehandler) { + set_error_handler(self::$_xmlrpcs_prev_ehandler); + self::$_xmlrpcs_prev_ehandler = null; + } else { + restore_error_handler(); } throw $e; case 1: @@ -953,14 +951,13 @@ class Server } } - if ($this->debug > 2) { - // note: restore the error handler we found before calling the user func, even if it has been changed - // inside the func itself - if (self::$_xmlrpcs_prev_ehandler) { - set_error_handler(self::$_xmlrpcs_prev_ehandler); - } else { - restore_error_handler(); - } + // note: restore the error handler we found before calling the user func, even if it has been changed + // inside the func itself + if (self::$_xmlrpcs_prev_ehandler) { + set_error_handler(self::$_xmlrpcs_prev_ehandler); + self::$_xmlrpcs_prev_ehandler = null; + } else { + restore_error_handler(); } return $r; @@ -974,7 +971,7 @@ class Server * @internal * @param $methodName * @param XMLParser $xmlParser - * @param resource $parser + * @param null|resource $parser * @return void * @throws NoSuchMethodException * @@ -982,7 +979,7 @@ class Server * dirtying a lot the logic, as we would have back to both parseRequest() and execute() methods the info * about the matched method handler, in order to avoid doing the work twice... */ - public function methodNameCallback($methodName, $xmlParser, $parser) + public function methodNameCallback($methodName, $xmlParser, $parser = null) { $sysCall = $this->isSyscall($methodName); $dmap = $sysCall ? $this->getSystemDispatchMap() : $this->dmap; diff --git a/tests/08ServerTest.php b/tests/08ServerTest.php index 95712196..074e2492 100644 --- a/tests/08ServerTest.php +++ b/tests/08ServerTest.php @@ -597,6 +597,7 @@ And turned it into nylon'; $m = new xmlrpcmsg('tests.generatePHPWarning', array( new xmlrpcval('whatever', 'string'), )); + $this->addQueryParams(array('FORCE_DEBUG' => 0)); $v = $this->send($m); if ($v) { $this->assertEquals(true, $v->scalarval());