From: Mischa POSLAWSKY Date: Wed, 13 Sep 2017 23:40:30 +0000 (+0200) Subject: page: catch fatal php errors X-Git-Tag: v2.1~7 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/42d01534123ab54ae8d2ceee5fe9357605b5e637 page: catch fatal php errors --- 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';