<?php

/* ===============================
GLOBAL ERROR DISPLAY (DEV MODE)
================================ */

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

/* ===============================
ERROR HANDLER (PHP ERRORS)
================================ */

set_error_handler(function ($severity, $message, $file, $line) {

    echo "<div style='background:#f8d7da;color:#721c24;padding:15px;margin:10px;border-radius:6px;'>";
    echo "<strong>PHP ERROR:</strong><br>";
    echo "Message: $message <br>";
    echo "File: $file <br>";
    echo "Line: $line";
    echo "</div>";

});

/* ===============================
EXCEPTION HANDLER (TRY/CATCH)
================================ */

set_exception_handler(function ($e) {

    echo "<div style='background:#f8d7da;color:#721c24;padding:15px;margin:10px;border-radius:6px;'>";
    echo "<strong>SYSTEM EXCEPTION:</strong><br>";
    echo "Message: " . $e->getMessage() . "<br>";
    echo "File: " . $e->getFile() . "<br>";
    echo "Line: " . $e->getLine();
    echo "</div>";

});

/* ===============================
SHUTDOWN HANDLER (FATAL ERRORS)
================================ */

register_shutdown_function(function () {

    $error = error_get_last();

    if ($error !== NULL) {

        echo "<div style='background:#f8d7da;color:#721c24;padding:15px;margin:10px;border-radius:6px;'>";
        echo "<strong>FATAL ERROR:</strong><br>";
        echo "Message: {$error['message']}<br>";
        echo "File: {$error['file']}<br>";
        echo "Line: {$error['line']}";
        echo "</div>";

    }

});