Skip to content

Provides tools to manage errors and ease debugging PHP code

License

Notifications You must be signed in to change notification settings

symfony/error-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

102be5e · Mar 3, 2025
Sep 25, 2024
May 17, 2024
Jun 20, 2024
Aug 6, 2024
Nov 5, 2024
Dec 12, 2022
Jan 7, 2025
Feb 2, 2025
Jul 6, 2024
Jul 18, 2019
Aug 26, 2024
Feb 28, 2024
Oct 18, 2023
Mar 3, 2025
Nov 5, 2024
Jan 24, 2023
Dec 8, 2023
Jun 29, 2021
Aug 5, 2023
Dec 19, 2022

Repository files navigation

ErrorHandler Component

The ErrorHandler component provides tools to manage errors and ease debugging PHP code.

Getting Started

composer require symfony/error-handler
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\ErrorHandler\DebugClassLoader;

Debug::enable();

// or enable only one feature
//ErrorHandler::register();
//DebugClassLoader::enable();

// If you want a custom generic template when debug is not enabled
// HtmlErrorRenderer::setTemplate('/path/to/custom/error.html.php');

$data = ErrorHandler::call(static function () use ($filename, $datetimeFormat) {
    // if any code executed inside this anonymous function fails, a PHP exception
    // will be thrown, even if the code uses the '@' PHP silence operator
    $data = json_decode(file_get_contents($filename), true);
    $data['read_at'] = date($datetimeFormat);
    file_put_contents($filename, json_encode($data));

    return $data;
});

Resources