Var_dump sucked.

Why I didn’t use var_dump() for a long time, even though it has very valuable information in it ?  You most probably guessed it. It looks terrible. Even when you fix it with adding <pre> tags around it, it’s still ugly.

Consider this code:

$fruits = array ( "fruits"  => array ( "a" => "orange",
                                       "b" => "banana",
                                       "c" => "apple"
                                     ),
                  "numbers" => array ( 1,
                                       2,
                                       3,
                                       4,
                                       5,
                                       6
                                     ),
                  "holes"   => array (      "first",
                                       5 => "second",
                                            "third"
                                     )
                );
var_dump($fruits);
die();

Well it is turned into this:

Plain var_dump

It’s ugly! It’s so ugly! There are no other words for it.

So I could never talk myself into using it, and because of that for the past few years, I did a print_r(), wrapped in those “pre” tags.

Until I saw a screencast by Jeffrey Way on Laravel, and I saw the single most beautiful var_dump in the history of mankind.

Pretty var_dump

Look at it! It’s so pretty! It’s the same data, but so much has changed!

So I wanted it too. After some googling, I found out, that it is a PHP Extension (that anyone can install) and not a Chrome extension (which was my initial guess). It’s called Xdebug, and you can get it at http://www.xdebug.org and you’ll probably want to read more about the installation ( http://xdebug.org/docs/install )

In addition, I initially thought, that I’d have some difficulties installing and setting Xdebug up, since I’m a MAMP user (I like graphical interfaces and all that good stuff, I just can’t help it, that’s why I am so excited about Xdebug after all). Turns out, that I was wrong (again).

Enabling Xdebug on MAMP (Pro) is as simple as, well – enabling Xdebug on MAMP (Pro). All you really have to do is:

  • Open MAMP
  • File -> Edit Template -> PHP -> PHP (your-version).ini
  • Go to the very bottom and uncomment the Xdebug extension (remove the semicolon at the beginning of the line), like so:
zend_extension="/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
  •  Restart MAMP

And That’s it! Enjoy!

 

  • That’s hilarious. I watched a Jeffrey Way tutorial too and was mind blown by the prettiness of his array output. Which lead me to Google, which then lead me to your blog post. thanks!

  • I too came here after watching a Jeffery Way tutorial…. One thing to note, make sure that you have html_errors = On set your php.ini. I’ve had Xdebug installed for months, and wasn’t seeing pretty output until I set that.

    Thanks for the tip!

Leave a Reply

Your email address will not be published. Required fields are marked *