Too much data with var_dump in symfony2 doctrine2
Asked Answered
P

9

108

I have around 40 entities and many bidirectional relationships. Whenever i use var_dump($user) or any entity my browser gets loaded with too much data of arrays and variables then it just crashed.

i want to whats the problem.

The data is being inserted fine. Can i cause issue in production.

Premillenarian answered 10/8, 2012 at 12:54 Comment(7)
What browser are we talking about?Skimp
Are you using xdebug? If not, consider to use it and instead of var_dump just make use of the step debugger with a IDE like Ecplipse, Netbeans or PHPStorm. All these will display the variables data nicely.Groove
What do you mean by "crashing" - does the browser application (or tab) close, or it display no result, or the page is interrupted?Achondrite
my browser displays very long page of variables data with all my entiies and all that. looks like it goes in never ending loop. i tried botf firefox and chrome. if i try any other class whic has no relation then it works ok but with many relationships it freezez the computer. i had to end task thatPremillenarian
I have a bare-bones class and my browser crashed too. I'm hating all these retarded defaults.Tyburn
This is also relevant for ZF2!Ga
xdebug is definitely what you need, yes!Kielty
S
233

Replace var_dump() with the debug method dump() provided by Doctrine Common.

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

It works for single objects and Doctrine collections and should prevent browser displaying issues you are having.

Simonsimona answered 11/8, 2012 at 10:28 Comment(4)
You can also dump() with MaxDepth, in dump() second argument is MaxDepth.Polytrophic
If you prefer to have the debug output in your php error log, use the following: error_log(print_r(\Doctrine\Common\Util\Debug::export($variable, $depth),1)); It's pretty cumbersome to type every time, but you can easily create a macro for it.Aggressor
This function is very helpful! Saved me from browser crashes as well.Secretin
This class is deprecated - you should use the Symfony var dumper insteadMyrticemyrtie
S
21

well formatted :

echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user, $recurciveLevelToDisplay);
echo '</pre>';
Stearne answered 28/6, 2013 at 8:25 Comment(0)
H
5

Simple and easy example.

var_dump(serialize($Object));
Hutch answered 13/11, 2015 at 0:8 Comment(0)
B
5

Symfony < 2.6

You can use \Doctrine\Common\Util\Debug::dump($variable, $depth); it displays doctrine output without the proxy information.

Symfony > 2.6

If you are using symfony 2.6 or more, I strongly advice you to use dump(). It shows a well formated and colored output, and you can dynamically expend/hide rows. enter image description here

Boon answered 6/12, 2016 at 7:37 Comment(0)
D
4

The problem is that in a bidirectional relationship both entities have a link to each other, so while displaying entity1 var_dump will also have to print all properties of entity2, which include entity1 itself giving you a loop.

Dylane answered 14/6, 2013 at 8:42 Comment(1)
This is the only answer that explain the WHY it happens.Ratoon
V
2

The get_object_vars() improve the visualization too.

echo "<pre>";
\Doctrine\Common\Util\Debug::dump(get_object_vars($user));
Vesuvian answered 17/9, 2014 at 17:53 Comment(0)
W
2

With Symfony 2.6 you can now just use dump($var) in your controller and {{ dump(var) }} in twig.

Make sure to add this to your AppKernal.php file, in the array('dev', 'test') section.

$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
Westleigh answered 30/4, 2015 at 2:17 Comment(0)
R
2

use dump($user) and you can see perfect result in Symfony Profiler! good luck

Rorrys answered 28/1, 2016 at 13:34 Comment(0)
S
1

Just use echo serialize($user);

Sorb answered 10/1, 2015 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.