Too much data with var_dump in symfony2 doctrine2

PhpDebuggingDoctrine OrmSymfony 2.1

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

well formatted :

echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user, $recurciveLevelToDisplay);
echo '</pre>';

Solution 3 - Php

Simple and easy example.

var_dump(serialize($Object));

Solution 4 - Php

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

Solution 5 - Php

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.

Solution 6 - Php

The get_object_vars() improve the visualization too.

echo "<pre>";
\Doctrine\Common\Util\Debug::dump(get_object_vars($user));

Solution 7 - Php

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();
 

Solution 8 - Php

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

Solution 9 - Php

Just use echo serialize($user);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMirageView Question on Stackoverflow
Solution 1 - PhpmgiagnoniView Answer on Stackoverflow
Solution 2 - PhpBouchehboun SaadView Answer on Stackoverflow
Solution 3 - PhpKentaro OhkouchiView Answer on Stackoverflow
Solution 4 - PhpgotoView Answer on Stackoverflow
Solution 5 - PhpRad80View Answer on Stackoverflow
Solution 6 - PhpWellington LorindoView Answer on Stackoverflow
Solution 7 - PhpJ-whoView Answer on Stackoverflow
Solution 8 - PhpVitaly PugachView Answer on Stackoverflow
Solution 9 - PhpAlexMView Answer on Stackoverflow