Pretty dump variable/object in Symfony 2.*?
Asked Answered
A

4

5

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?

Afforest answered 24/3, 2013 at 22:2 Comment(2)
no, you could install something like xdebug to do that automatically for you while using the var_dump function. The strength of Symfony2 is to use the best tools in the PHP community, instead of re-inventing the wheel.Glynis
In the end, I could build something for what I need, but I wanted to know if it is there already.Afforest
P
16
exit(\Doctrine\Common\Util\Debug::dump($someVar));
Piazza answered 20/5, 2014 at 23:57 Comment(0)
Z
8

use

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

Zealand answered 27/8, 2013 at 12:4 Comment(0)
A
5

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.

Attendant answered 24/3, 2013 at 22:29 Comment(1)
At the moment I am using Ladybug and it doesn't work well at all. I am not able to open all collapse... I tried on Chrome, FF and IE. Also I often get memory issue with this tool.Immobile
D
1

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

Descendible answered 3/12, 2015 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.