0

I want to print entities in PHP for debug purposes with print_r() or var_dump(). The entities are loaded via doctrine/symfony from the database and some of them have a lot of attributes attached. Example:

file
- id
- name
- extension
- fileGroups
- ...

fileGroups is a list of objects of another entity:

fileGroup
- id
- name
- client
- ...

Client is a another entity ... and so forth.

Now when I execute print_r($file), I would like to have only the first list of attributes printed and not the ones below in the hierarchy (because that causes a lazy loading and a memory error in many cases and I'm not interested in that data in the first place).

Is there a possibility to tell PHP to only print certain attribute hierarchies (like only first hierarchy or first and second)? Or is there a way to tell doctrine to not load attributes (maybe with a parameter), if they are printed via PHP?

Mathias Bader
  • 3,585
  • 7
  • 39
  • 61

1 Answers1

1

You can use:

\Doctrine\Common\Util\Debug::dump($variable, 1);
eselskas
  • 808
  • 8
  • 17
  • 1
    That works, thanks. But it tells me the method is deprecated and [Symfony var dumper](https://symfony.com/doc/current/components/var_dumper.html) should be used instead. The Symfony var dumper is what I was looking for. Nice! – Mathias Bader Sep 06 '22 at 18:19