From b2bfd47df322193e39efe1a7c1a2ff25c3970ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no> Date: Wed, 6 Jul 2016 11:41:32 +0200 Subject: [PATCH] bugfix: Exception handler compatible with PHP 7. PHP 7 changed the way it handles internal errors. Now, Exception objects inherit from the Throwable interface, as well as the new Error objects. Internal functions throw Error objects now instead of raising an error, so the exception handler would need to handle them as well. Therefore, the exception handler is no longer guaranteed to receive an Exception object. We need now to discern whether the parameter is an exception (and continue our business as usual), or an Error (in case such thing exists, only PHP 7), and in this last case parse it and let the error handler do its stuff. This should resolve #330. --- www/_include.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/www/_include.php b/www/_include.php index 3b8e056c9..8a5bf9be0 100644 --- a/www/_include.php +++ b/www/_include.php @@ -35,15 +35,23 @@ require_once(dirname(dirname(__FILE__)).'/lib/_autoload.php'); SimpleSAML_Error_Assertion::installHandler(); // show error page on unhandled exceptions -function SimpleSAML_exception_handler(Exception $exception) +function SimpleSAML_exception_handler($exception) { SimpleSAML\Module::callHooks('exception_handler', $exception); if ($exception instanceof SimpleSAML_Error_Error) { $exception->show(); - } else { + } elseif ($exception instanceof Exception) { $e = new SimpleSAML_Error_Error('UNHANDLEDEXCEPTION', $exception); $e->show(); + } else { + if (class_exists('Error') && $exception instanceof Error) { + $errno = $exception->getCode(); + $errstr = $exception->getMessage(); + $errfile = $exception->getFile(); + $errline = $exception->getLine(); + SimpleSAML_error_handler($errno, $errstr, $errfile, $errline); + } } } -- GitLab