From 42d01534123ab54ae8d2ceee5fe9357605b5e637 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 14 Sep 2017 01:40:30 +0200 Subject: [PATCH] page: catch fatal php errors --- page.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/page.php b/page.php index 856a08a..4944467 100644 --- a/page.php +++ b/page.php @@ -2,12 +2,20 @@ error_reporting(E_ALL); ini_set('display_errors', TRUE); -set_exception_handler(function ($error) { +function fail($error) +{ http_response_code(500); include_once 'page.inc.php'; ob_start(); require_once './500.html'; print str_replace('[[debug]]', $error, ob_get_clean()); +} +set_exception_handler('fail'); +register_shutdown_function(function () { + # display failure page for fatal exceptions + $error = error_get_last(); + if (!($error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))) return; + fail("Fatal: $error[message] in $error[file]:$error[line]"); }); include_once 'auth.inc.php'; -- 2.30.0