The Debug ComponentEdit this page
Warning: You are browsing the documentation for Symfony 2.3, which is no longer maintained.
Read the updated version of this page for Symfony 6.3 (the current stable version).
The Debug Component
The Debug component provides tools to ease debugging PHP code.
The Debug component was introduced in Symfony 2.3. Previously, the classes were located in the HttpKernel component.
You can install the component in many different ways:
- Install it via Composer (
- Use the official Git repository (https://github.com/symfony/debug).
Then, require the
vendor/autoload.php file to enable the autoloading mechanism
provided by Composer. Otherwise, your application won't be able to find the classes
of this Symfony component.
The Debug component provides several tools to help you debug PHP code. Enabling them all is as easy as it can get:
1 2 3
use Symfony\Component\Debug\Debug; Debug::enable();
The enable() method registers an error handler and an exception handler. If the ClassLoader component is available, a special class loader is also registered.
Read the following sections for more information about the different available tools.
You should never enable the debug tools in a production environment as they might disclose sensitive information to the user.
Enabling the Error Handler
The ErrorHandler class catches PHP errors and converts them to exceptions (of class ErrorException or FatalErrorException for PHP fatal errors):
1 2 3
use Symfony\Component\Debug\ErrorHandler; ErrorHandler::register();
Enabling the Exception Handler
The ExceptionHandler class catches uncaught PHP exceptions and converts them to a nice PHP response. It is useful in debug mode to replace the default PHP/XDebug output with something prettier and more useful:
1 2 3
use Symfony\Component\Debug\ExceptionHandler; ExceptionHandler::register();
If the HttpFoundation component is available, the handler uses a Symfony Response object; if not, it falls back to a regular PHP response.