Hey I love this package!

I find it useful to use print_r() to get a good look at mysterious and/or buggy data structures. But I find the dprint_r() method you've included not quite enough. You can't control enough where it gets printed. What I do is add a theme method to pretty print variables. It let's me add code like this:

drupal_set_message(theme('devel', $obj)); // debug!

Anyway, here's a patch to do what I'm talking about. I hope it benefits others.

CommentFileSizeAuthor
theme_devel.patch776 bytesDave Cohen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

where do you usually print the message? at first glance, i don't see that much value here.

Dave Cohen’s picture

When I'm trying to track something down I often end up printing several messages. If I use print() they end up on the top of the page, often obscured by an absolutely positioned logo. If I use drupal_set_message(), they appear in a nice place, in the order I printed them, and even if I later perform a drupal_goto(), I see the messages on the next page. (Less need for that now thanks to the devel package.)

All my patch does is wrap the print_r() in an output buffer and return the string so it can be displayed later, when the page is being themed. You can take it or leave it, I won't be offended.

Dave Cohen’s picture

Also, you can use the theme function to insert an print_r into a watchdog message. But I'll shut up now.

merlinofchaos’s picture

I would be just as happy if dprint and dprint_r could print the messages down with the SQL debug messages rather than at the top.

moshe weitzman’s picture

Status: Needs review » Closed (won't fix)

both sprint and dprint_r() can return strings instead of printing thus you can use drupalset_message on its return value if you wish.

Senpai’s picture

And just how would you go about this in a smooth, easy, and pretty way? This patch seems to hand things off to the theme layer for display, but by marking it as Won't Fix, it would appear that there's another way to do this same thing that's easier than the suggested patch.

So what is it? Can you give a quick example, please?