|
| 1 | +.. index:: |
| 2 | + single: Debug |
| 3 | + single: Components; Debug |
| 4 | + |
| 5 | +The Debug Component |
| 6 | +=================== |
| 7 | + |
| 8 | + The Debug Component provides tools to ease debugging PHP code. |
| 9 | + |
| 10 | +.. versionadded:: 2.3 |
| 11 | + The Debug Component is new to Symfony 2.3. Previously, the classes were |
| 12 | + located in the ``HttpKernel`` component. |
| 13 | + |
| 14 | +Installation |
| 15 | +------------ |
| 16 | + |
| 17 | +You can install the component in many different ways: |
| 18 | + |
| 19 | +* Use the official Git repository (https://github.com/symfony/Debug); |
| 20 | +* :doc:`Install it via Composer </components/using_components>` (``symfony/debug`` on `Packagist`_). |
| 21 | + |
| 22 | +Usage |
| 23 | +----- |
| 24 | + |
| 25 | +The Debug component provides several tools to help you debug PHP code. |
| 26 | +Enabling them all is as easy as it can get:: |
| 27 | + |
| 28 | + use Symfony\Component\Debug\Debug; |
| 29 | + |
| 30 | + Debug::enable(); |
| 31 | + |
| 32 | +The :method:`Symfony\\Component\\Debug\\Debug::enable` method registers an |
| 33 | +error handler and an exception handler. If the :doc:`ClassLoader component |
| 34 | +</components/class_loader>` is available, a special class loader is also |
| 35 | +registered. |
| 36 | + |
| 37 | +Read the following sections for more information about the different available |
| 38 | +tools. |
| 39 | + |
| 40 | +.. caution:: |
| 41 | + |
| 42 | + You should never enable the debug tools in a production environment as |
| 43 | + they might disclose sensitive information to the user. |
| 44 | + |
| 45 | +Enabling the Error Handler |
| 46 | +-------------------------- |
| 47 | + |
| 48 | +The :class:`Symfony\\Component\\Debug\\ErrorHandler` class catches PHP errors |
| 49 | +and converts them to exceptions (of class :phpclass:`ErrorException` or |
| 50 | +:class:`Symfony\\Component\\Debug\\Exception\\FatalErrorException` for PHP |
| 51 | +fatal errors):: |
| 52 | + |
| 53 | + use Symfony\Component\Debug\ErrorHandler; |
| 54 | + |
| 55 | + ErrorHandler::register(); |
| 56 | + |
| 57 | +Enabling the Exception Handler |
| 58 | +------------------------------ |
| 59 | + |
| 60 | +The :class:`Symfony\\Component\\Debug\\ExceptionHandler` class catches |
| 61 | +uncaught PHP exceptions and converts them to a nice PHP response. It is useful |
| 62 | +in debug mode to replace the default PHP/XDebug output with something prettier |
| 63 | +and more useful:: |
| 64 | + |
| 65 | + use Symfony\Component\Debug\ExceptionHandler; |
| 66 | + |
| 67 | + ExceptionHandler::register(); |
| 68 | + |
| 69 | +.. note:: |
| 70 | + |
| 71 | + If the :doc:`HttpFoundation component </components/http_foundation>` is |
| 72 | + available, the handler uses a Symfony Response object; if not, it falls |
| 73 | + back to a regular PHP response. |
| 74 | + |
| 75 | +.. _Packagist: https://packagist.org/packages/symfony/debug |
0 commit comments