Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-58843

Exception handlers must not expect Exception instances only

    XMLWordPrintable

    Details

      Description

      I have discovered this while debugging MDLSITE-5026. On moodle.net, we have error_log records like

      PHP Fatal error:  Uncaught TypeError: Argument 1 passed to webservice_xmlrpc_server::generate_error() must be an instance of Exception, instance of Error given, called in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php on line 139 and defined in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php:170
       
      Stack trace
      #0 /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php(139): webservice_xmlrpc_server->generate_error(Object(Error))
      #1 /var/www/vhosts/moodle.net/html/webservice/lib.php(1245): webservice_xmlrpc_server->send_error(Object(Error))
      #2 [internal function]: webservice_base_server->exception_handler(Object(Error))
      #3 {main}\n  thrown in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php on line 170
      

      As documented at http://php.net/manual/en/function.set-exception-handler.php, starting with PHP 7 the custom exception handlers are passed with Error instances beside the Exception instances (both of them implement Throwable).

      I suggest to do what PHPUnit did (https://github.com/sebastianbergmann/phpunit/commit/c3db067ba2f64843d6038c6dc9c51eca794f5e06) and get rid of the Exception type declaration in the handler signature.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mudrd8mz David Mudrák (@mudrd8mz)
                Reporter:
                mudrd8mz David Mudrák (@mudrd8mz)
                Peer reviewer:
                Ankit Agarwal
                Integrator:
                David Monllaó
                Tester:
                CiBoT
                Participants:
                Component watchers:
                Carlos Escobedo, Mark Nelson, Juan Leyva, Jake Dallimore, Jun Pataleta
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Jul/17