WARNING: You are browsing the documentation for Symfony 4.1 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

The Debug Component

4.1 version

The Debug Component

The Debug component provides tools to ease debugging PHP code.


$ composer require symfony/debug

Alternatively, you can clone the https://github.com/symfony/debug repository.


If you install this component outside of a Symfony application, you must require the vendor/autoload.php file in your code to enable the class autoloading mechanism provided by Composer. Read this article for more details.


The Debug component provides several tools to help you debug PHP code. Enabling them all can be done by calling the static method Debug::enable():

use Symfony\Component\Debug\Debug;


The enable() method registers an error handler, an exception handler and a special class loader.

Read the following sections for more information about the different available tools.


You should never enable the debug tools, except for the error handler, in a production environment as they might disclose sensitive information to the user.

Enabling the Error Handler

The Symfony\Component\Debug\ErrorHandler class catches PHP errors and converts them to exceptions (of class ErrorException or Symfony\Component\Debug\Exception\FatalErrorException for PHP fatal errors):

use Symfony\Component\Debug\ErrorHandler;


This error handler is enabled by default in the production environment when the application uses the FrameworkBundle because it generates better error logs.

Enabling the Exception Handler

The Symfony\Component\Debug\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:

use Symfony\Component\Debug\ExceptionHandler;



If the HttpFoundation component is available, the handler uses a Symfony Response object; if not, it falls back to a regular PHP response.

Debugging a Class Loader

The Symfony\Component\Debug\DebugClassLoader attempts to throw more helpful exceptions when a class isn’t found by the registered autoloaders. All autoloaders that implement a findFile() method are replaced with a DebugClassLoader wrapper.

To activate the DebugClassLoader, call its static enable() method:

use Symfony\Component\Debug\DebugClassLoader;


This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.