PDA

View Full Version : my take on a better print_r() and var_dump()


Leeoniya
06-21-2011, 10:38 PM
hello fellow PHPers,

finally i got around to making something which i feel is a much improved, lightweight and tweakable combo of print_r() and var_dump(). i bet 90% use-cases for these functions dump into a browser, not a text editor, so why not use everything HTML/js has to offer?

there are plenty of other alternatives (dBug (http://dbug.ospinto.com/), debuglib (http://phpdebuglib.de/debuglib.php), wtUtil (http://redotheoffice.com/?p=65), krumo (http://krumo.sourceforge.net/), kint (http://code.google.com/p/kint/), php dump (http://jacksleight.com/old/assets/blog/really-shiny/scripts/php-dump.txt), Debug::dump (http://codeaid.net/php/improved-var_dump%28%29-with-colored-output)), but none that lived up to my minimalist, lightweight, configurable and non-verbose desires. dump_r is completely CSS-styled, plus there are additional classes added that can usefully categorize items such as "type" "subtype" "empty" "numeric"

currently, the functionality is more-than-adequate, but is always a work in progress. i have my TODO list in the Issues section. feel free to fork, make pull requests or report any bugs or enhancements.

for folding/unfolding, the example page links jQuery 1.6.1 and uses a small dump_r.js file to initialize the click handlers. it would be pretty easy to kill the jQuery dependency with some good ole' fashion plain DOM js, but i didn't feel like it since most of my projects already have it loaded :)

https://github.com/leeoniya/dump_r.php

would love some feedback. happy dumping!
leon

Inigoesdr
06-21-2011, 10:50 PM
It's definitely minimalist. :)

If I were going to use something outside of the core functions for dumping I generally use dBug because I find the cfdump-style a lot easier to read for larger objects. But, I'm sure this will be useful to people.

Leeoniya
06-21-2011, 11:34 PM
thx! but ouch, screenshot with cleartype/D2D rendering makes eyes hurt :(

i attached a clearer + fuller png to OP

Leeoniya
12-23-2011, 12:49 AM
some refactoring and quite a few improvements made. including circular references, relative date indicators, callbacks, xml namespace stripping, removed jquery dependency for folding interaction, moved all code to a single file for easy inclusion.

attaching updated sample image, since i can't seem to edit the original post here.

Durex
01-27-2012, 06:31 PM
The second one is much better.
Much more clean and that makes it more clear.
It will be very useful for a lot of people.

Leeoniya
01-27-2012, 07:36 PM
you can modify the css stylesheet to your needs - it can be made to look as clean as you'd like.

EDIT: also, welcome to CF!