// Пользовательский обработчик ошибок (warnings, notices)
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
// Глобальный обработчик исключений (если не поймали в try/catch)
set_exception_handler(function (Throwable $e) {
error_log(sprintf("[%s] %s in %s:%d", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()));
if (php_sapi_name() !== 'cli') {
http_response_code(500);
echo 'Internal Server Error';
}
});
// Для фатальных ошибок (E_ERROR, E_PARSE) - register_shutdown_function
register_shutdown_function(function () {
$error = error_get_last();
if ($error && ($error['type'] & (E_ERROR | E_PARSE | E_COMPILE_ERROR))) {
error_log("Fatal: {$error['message']}");
}
});