Wednesday 5 March 2014

Debugging quickie: Objects

How do you display the contents of an object that has private and protected properties - which means dpm($object) doesn't give you what you want?

You could do this:

dpm('<pre>' . print_r($object, TRUE) . '</pre>');

But that's a lot to type and you get a huge horrible list (particularly if it's a View object).

Try this instead:

dpm((array) $object);

Works a treat.

And while we're on the subject of dpm() have you tried this:

dpm($var, __FUNCTION__);

or

dpm($var, __METHOD__);

It can help.