Using the Symfony VarDumper Component For Debugging

What is the Symfony VarDumper Component?

The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. Built on top, it provides a better dump() function that you can use instead of var_dump.

Please visit the official documentation page for more detailed information about this Symfony component.

How can I install the Symfony VarDumper Component?

The quickest and easiest way is to find the package on packigst website and then use composer to install the package to your project.

To install to your project, run the following command on either Windows or Linux in the command line.

This will add the current stable package to your project and will generate an updated autoload.php file in your vendors folder.

How do I use the Symfony VarDumper Component?

To use the VarDumper component, you must make some small changes to your AppKernel.php file, you will find this in your projects app folder.

Find the following section of code:

Now add to the code as shown in the example below:

This will now allow you to use the VarDumper Component in your project and output information to the profiler bar.

This component can be used in your project files as the method dump()  is globally available from the component, you can also use the component in the command line interface too and the output will be written to STDOUT .

How to Use the Dump Method

If for example I had an entity in my project called Order and I was wanting to view the loaded entity from the database, the easiest way of achieving this would be like so:

Resulting in the following output to the profiler bar:

Symfony Profiler Dump

This is quite a useful Symfony component and can be used in any project whether it is Symfony based or not, as long as it is a PHP project, go away and play with it, enjoy!