Output Contents Of A Doctrine Object
I've being doing a lot of development with Doctrine recently and one of the things that I found out is that the Objects it works with can be huge which makes debugging the objects quite difficult for you and the browser to process.
If you haven't used Doctrine before you really should give it a try. Doctrine is essentially a set of PHP class libraries that are focused on database storage and database management. The main projects with Doctrine are the ORM (Object Relational Manager) and DBAL (Database Abstraction Layer). Using these two projects Doctrine allows you to build up database entities in PHP code that will represent your application's database structure.
Having PHP classes to construct your database structure means that you can use fully object oriented code to construct the Database queries, this provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.
As the database structure is built using PHP Objects it will include all column types, primary keys, indexes and joins in the PHP object. This can be a lot of information needed to be stored inside the object, if you have joins in your table then there is more information about the join and all the information about the joining table.
When working with Doctrine objects, you might want to debug the object and see what's inside it at a certain time in your application so you output the content of the object with a var_dump() or a print_r().
But because of the size of the objects the output could crash your browser because there is too much information to output.
There is a utility class in doctrine that allows you to debug your Doctrine entities so that you can output the contents just like a print_r(), just use the following snippet, providing it with the entity object and the max depth you want to output.
Learn how to code with Treehouse
- Learn projects with access to 1000+ videos
- Practice live with our Code Challenge Engine
- Get help in our members-only forums
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.
Subscribe today and get a 50% discount code to Paulund