Alex Rivera | Logout

Is there a pretty print for PHP?

Asked 2009-07-22T20:52:41.757
110

I'm fixing some PHP scripts and I'm missing ruby's pretty printer. i.e.

require 'pp'
arr = {:one => 1}
pp arr

will output {:one => 1}. This even works with fairly complex objects and makes digging into an unknown script much easier. Is there some way to duplicate this functionality in PHP?

Edit
Report

4 Answers

7

How about print_r?

http://www.php.net/print_r

answered 2009-07-22T20:54:01.877
3
error_log(print_r($variable,true));

to send to syslog or eventlog for windows

answered 2009-07-22T22:17:39.493
3

If you're doing more debugging, Xdebug is essential. By default it overrides var_dump() with it's own version which displays a lot more information than PHP's default var_dump().

There's also Zend_Debug.

answered 2009-07-22T23:03:38.653
-2

I use this function for debugging:

function pre($pre=true) {
    if($pre) {
        echo "<pre>";
    }
    foreach(func_get_args as $arg) {
        print_r($arg);
        # or, if it pleases you more:
        # var_dump(arg); 
    }
    if($pre) {
        echo "<pre>";
    }

}

This way you don't have to

pre($arrayOne);
pre($arrayTwo);

But in one go:

pre($arrayOne, $arrayTwo); 

Or as many arguments you give it.

answered 2012-10-15T19:28:07.563

Your Answer