Krumo: version 2.0 of print_r(); and var_dump();

Overview

To put it simply, Krumo is a replacement for print_r() and var_dump(). By definition Krumo is a debugging tool (initially for PHP4/PHP5, now for PHP5 only), which displays structured information about any PHP variable.

A lot of developers use print_r() and var_dump() in the means of debugging tools. Although they were intended to present human readble information about a variable, we can all agree that in general they are not. Krumo is an alternative: it does the same job, but it presents the information beautified using CSS and DHTML.

Except the collapsible DHTML tree built around the structure of the dumped PHP variable, and the improved by the CSS looks, Krumo offers additional useful features.

For example haven't been disappointed that you can not see the name of the variable passed for dumping ? Calling it many times, you will not be able to know which dump value was provided by a certain variable at a certain time in a certain place of your code. Well, Krumo can not do that either, but it offers a work- around: it prints the code line that the Krumo call was placed: in this way you can keep track of the origin of each dump you see on the screen.

Another nice addition to the set of Krumo features is the ability to turn it off. When your code gets swamped with a lot of dumping calls, instead of cleaning them up, you can just turn them off. You go to admit that this beats the alternative of going through your code and removing every dumping route you have ... right ?

A lot of times you need to dump the contents of the superglobals ($_GET, $_POST, $_SERVER, $_SESSION, etc), or see the list of included files, or the declared classes and interfaces, or the defined constants, etc. Krumo offers an easy, fast and graceful way to do this with just one simple call: see the examples area for demonstration, or just load this page to see the results.

^ back to the top of the page

Install

In order to use Krumo you have to put it on your (development) server, and include it in your script. You can put it somewhere in the INCLUDE_PATH, or specify the full path to the class.krumo.php file.

You have to modify the krumo.ini file too. It is the configuration file for Krumo. The first option is choosing a skin:

 [skin]
 selected = "orange"

The value for this setting has to be the name of one of the sub-folders from the Krumo/skins/ folder. If the value provided for the skin results in not finding the skin, the `default` skin will be used instead.

The second option is used to set the correct web path to the folder where Krumo is installed. This is used in order to make the images from Krumo's CSS skins web-accessible.

 [css]
 url = "http://www.example.com/Krumo/"

So far those two are the only configuration options.

All the CSS files ("skin.css") from the Krumo/skins sub-folders must have the proper permissions in order to be readable from Krumo. Same applies for krumo.ini and krumo.js files.

^ back to the top of the page

Examples

Here's a basic PHP example, which will return a report on the array variable passed as argument to it:

 krumo(array('a1'=> 'A1', 3, 'red'));
  • ... (Array, 3 elements)
  • Krumo version 0.2a
    | http://krumo.sourceforge.net
    Called from /home/kinobg/krumo.mrasnika.info/index.php, line 267  

You can dump simultaneously more then one variable - here's another PHP example:

 krumo($_SERVER, $_ENV);

You probably saw from the PHP examples above that some of the nodes are expandable, so if you want to inspect the nested information, click on them and they will expand; if you do not need that information shown simply click again on it to collapse it. Here's a PHP example to test this:

 $x1->x2->x3->x4->x5->x6->x7->x8->x9 = 'X10';
 krumo($x1);
  • ... (Object) stdClass
  • Krumo version 0.2a
    | http://krumo.sourceforge.net
    Called from /home/kinobg/krumo.mrasnika.info/index.php, line 287  

The krumo() is the only standalone PHP function from the package, and this is because basic dumps about variables (like print_r() or var_dump()) are the most common tasks such functionality is used for. The rest of the functionality can be called using static calls to the Krumo class. Here are several more PHP examples:

 // print a debug backgrace
 krumo::backtrace();

 // print all the included(or required) files
 krumo::includes();

 // print all the included functions
 krumo::functions();

 // print all the declared classes
 krumo::classes();

 // print all the defined constants
 krumo::defines();

... and so on, etc.

For all the available features, check Krumo docs. A full PHPDocumenter API documentation exists both in this package and here, at the project's website: go and check the documentation section.

To see a PHP demonstration of most features, click here.

Another handy feature is that you can enable and disable Krumo no the fly.

 // disable Krumo
 krumo::disable();

 // Krumo is disabled, nothing is printed
 krumo::includes();

 // enable Krumo
 krumo::enable();

 // Krumo is enable, printing is OK
 krumo::classes();

This proves to be very useful when your PHP code gets swamped with Krumo calls dumping debuging information, and instead of removing each of those dumps one by one, you can just disable them.

^ back to the top of the page

Skins

There are several skins pre-installed with this package, but if you wish you can create skins of your own. The skins are simply CSS files that are prepended to the result that Krumo prints. If you want to use images in your CSS (for background, list-style, etc), you have to put %URL% in front of the image URL in order hook it up to the skin folder and make the image web-accessible.

Here's an example:

 ul.krumo-first {background: url(%url%bg.gif);}

Right now there are 4 Krumo skins (click on each to see a screenshot): default, blue, green, orange and the latest - schablon.com

Feel free to contribute any new skins that you create on your own. Krumo is designed to present the PHP variable dumps in a nice and graceful way, so polishing its looks with new themes is a very important task.

^ back to the top of the page

Documentation

The documentation for the Krumo project can be found inside the download packages.

To browse the site copy of Krumo docs, click here.

^ back to the top of the page

Download

You can dowbload the latest relese of Krumo from the project's download page at SourceForge.net. To do that, use the link below:

http://sourceforge.net/project/showfiles.php?group_id=194198

^ back to the top of the page

Bug Tracker

For the Krumo project, we are using the SourceForge.net tracker. If you want to report a bug, request a new feature, or you have ideas about improving the framework, use the link below:

http://sourceforge.net/tracker/?group_id=194198

^ back to the top of the page

Forums

For the Krumo project, we are using the SourceForge.net forums. If you want to drop a line, use the link below:

http://sourceforge.net/forum/?group_id=194198

^ back to the top of the page
SourceForge.net Logo
Krumo: Version 2.0 of print_r(); and var_dump();