Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty dump variable/object in Symfony 2.*?

When developing stuff I need to output the state of some instance in order to inspect it.

While using CakePHP I always had a debug() function which does some kind of var_dump inside a <pre> html element, so the content is readable.

Is something similar in Symfony 2.x too?

like image 689
Michael Avatar asked Mar 24 '13 22:03

Michael


4 Answers

exit(\Doctrine\Common\Util\Debug::dump($someVar));
like image 96
Pedro Luz Avatar answered Oct 24 '22 22:10

Pedro Luz


use

\Doctrine\Common\Util\Debug::dump($user);

like image 8
JasperZelf Avatar answered Oct 24 '22 23:10

JasperZelf


As of today, one of the best ways to debug in Symfony that I know of is the Ladybug Bundle. Its output is similar to xdebug's, but it has some nice features, like a collapsible tree structure for arays or automatically linking to documentation pages (supporting standard PHP, Doctrine and Symfony).

You can find some great examples of its use on the README.

like image 5
Diego Agulló Avatar answered Oct 25 '22 00:10

Diego Agulló


Now there is a new function in Symfony - dump(), have a look at http://symfony.com/blog/new-in-symfony-2-6-vardumper-component

like image 1
spectrumcat Avatar answered Oct 25 '22 00:10

spectrumcat