El componente Debug

El componente Debug proporciona herramientas para facilitar la depuración del código PHP.

Nuevo en la versión 2.3: El componente Debug es nuevo en Symfony 2.3. Anteriormente, las clases se localizaban en el componente HttpKernel.

Instalando

Puedes instalar el componente de varias maneras diferentes:

Usando

The Debug component provides several tools to help you debug PHP code. Enabling them all is as easy as it can get:

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.

Prudencia

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 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;

ErrorHandler::register();

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;

ExceptionHandler::register();

Nota

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

Bifúrcame en GitHub