Kint for PHP is a tool designed to present your debugging data in the absolutely best way possible.
In other words, it's
debug_backtrace() on steroids. Easy to use, but
powerful and customizable. An essential addition to your development toolbox.
Still lost? You use it to see what's inside variables.
<?php require '/kint/Kint.class.php'; Kint::dump( $_SERVER );
d( $variable1, $variable2 );
Kint intelligently detects what kind of data is being dumped and can provide tailored alternatives to otherwise hardly readable data.
Just a subset of available content aware features:
You are presented with a collapsible trace leading up to your call, you get to see the actual code of each step, the full dump of arguments that were passed, and - if available - the object which contained the method that was called.
PHP 5+ (extra functionality with 5.3+); modern era browser; optionally
support for better character detection.
Simply place the kint directory anywhere comfy and include the Kint.class.php file from there.
<?php require '/kint/Kint.class.php'; Kint::dump( $_SERVER ); // or, even easier, use a shorthand: d( $_SERVER ); // or, to seize execution after dumping use dd(); dd( $_SERVER ); // same as d( $_SERVER ); die; // to see trace: Kint::trace(); // or pass 1 to a dumper function Kint::dump( 1 ); // to disable all output Kint::enabled(false); // further calls, this one included, will not yield any output d('Get off my lawn!'); // no effect
You can optionally copy the included
config.default.php and rename to
config.php to override default values, but that's, again, entirely optional and you're
fine without this step.
Each option is heavily documented in the configuration file.
To output variable info in a lightweight, HTML-free fashion use
<?php s( $variable ); // and sd( $variable ); // to exit immediately afterwards
The output is whitespace-formatted and uses no HTML/CSS/JS. It still HTML-escapes variables though.
Kint also uses a non-standard PHP feature: modifiers. This is not a language feature; Kint achieves that by analyzing code that was used to call the dump functions (long story :).
<?php +Kint::dump( $variable ); // or, as usual +d( $variable );
+Kint::dump();will bypass the nesting depth limit.
*DEPTH TOO GREAT*messages, use this modifier to ignore them for that one call.
-Kint::dump();will clean all previous output to screen before displaying the dump.
ob_start()are used beforehand.
@Kint::dump();will return the output of the Kint::dump() instead of displaying it on screen.
!Kint::dump();will display the dump expanded by default so you don't have to click :)
Kint is usually effortless to install (see Laravel 4 example), but contributors have provided integration plugins for some platforms. In no particular order:
If you have integrated Kint into a framework or CMS, I'd be really grateful if you notified me via my email below or in the comments section, I'd add a link here too.
Disclaimer: I do not manage any of these repositories.
This tool is used heavily in real life development and constantly improved. Issues and feature requests are very welcome.
You should probably avoid using this tool in non-development environment settings, I cannot be held responsible for the performance, security and/or stability issues Kint may cause.
Original design by Mindaugas Stankaitis.
See contributors on Github.
Check out an awesome universal source decoder by a friend of mine.
Rokas Šleinius a.k.a. Raveren
Kint is licensed under the MIT License.