VOOZH about

URL: https://kint-php.github.io/kint/

โ‡ฑ Kint | Advanced PHP dumper


Kint - Advanced PHP dumper

What is it?

Kint is a dumper in the vein of var_dump, with keyboard controls, search, access path provision, and automatic data parsing.

๐Ÿ‘ Image

Install with composer

composer require kint-php/kint
<?php

include 'vendor/autoload.php';

d('Dumped with Kint');

Install a phar file

<?php

// Found in the build folder
include 'kint.phar';

d('Dumped with Kint');

Basic usage

<?php

Kint::dump($GLOBALS, $_SERVER); // Dump any number of variables
d($GLOBALS, $_SERVER); // d() is a shortcut for Kint::dump()

Kint::trace(); // Dump a backtrace

Kint::$enabled_mode = false; // Disable kint

Live demo

You have some data and you need to get more data out of it, but you donโ€™t know how the data is structured until you poke around inside it.

<?php

$time = get_mysterious_value();
$data = get_mysterious_data();
$object = get_mysterious_object();

include 'kint.phar';

d($time, $data, $object);

This output was pre-recorded

$time integer 1486849709
2017-02-11T21:48:29+00:00
$data string (740) "eyJjb2xvciI6InJnYmEoMjU1LCAyNTUsIDAsIDAuNSkiLCJkYXRhIjpbeyJ1c2VybmFtZSI6Im1v...
  • Base64
  • Contents
  • base64_decode($data) string (555) "{"color":"rgba(255, 255, 0, 0.5)","data":[{"username":"monkey","created":"20...
    base64_decode($data)
    • Json (2)
    • Contents
    • color => string (22) "rgba(255, 255, 0, 0.5)"
      json_decode(base64_decode($data), true)['color']
      yellow
      #FF0
      #FFFF00
      #FFFF0080
      rgba(255, 255, 0, 0.5)
      hsla(60, 100%, 50%, 0.5)
      
      data => array (6)
      json_decode(base64_decode($data), true)['data']
      • Table (6)
      • Contents (6)
      • usernamecreatedlastlog
        0monkey2017-01-25 22:24:082017-01-28 14:49:51
        1tiger2017-01-03 11:40:502017-01-09 17:44:48
        2mantis2017-01-03 12:19:482017-01-10 14:46:51
        3snake2017-01-11 22:15:252017-02-06 01:45:46
        4crane2017-01-09 22:28:342017-01-22 00:12:26
        5panda2017-01-14 13:20:402017-01-27 23:14:40
      • 0 => array (3)
        json_decode(base64_decode($data), true)['data'][0]
        username => string (6) "monkey"
        json_decode(base64_decode($data), true)['data'][0]['username']
        created => string (19) "2017-01-25 22:24:08"
        json_decode(base64_decode($data), true)['data'][0]['created']
        lastlog => string (19) "2017-01-28 14:49:51"
        json_decode(base64_decode($data), true)['data'][0]['lastlog']
        1 => array (3)
        json_decode(base64_decode($data), true)['data'][1]
        username => string (5) "tiger"
        json_decode(base64_decode($data), true)['data'][1]['username']
        created => string (19) "2017-01-03 11:40:50"
        json_decode(base64_decode($data), true)['data'][1]['created']
        lastlog => string (19) "2017-01-09 17:44:48"
        json_decode(base64_decode($data), true)['data'][1]['lastlog']
        2 => array (3)
        json_decode(base64_decode($data), true)['data'][2]
        username => string (6) "mantis"
        json_decode(base64_decode($data), true)['data'][2]['username']
        created => string (19) "2017-01-03 12:19:48"
        json_decode(base64_decode($data), true)['data'][2]['created']
        lastlog => string (19) "2017-01-10 14:46:51"
        json_decode(base64_decode($data), true)['data'][2]['lastlog']
        3 => array (3)
        json_decode(base64_decode($data), true)['data'][3]
        username => string (5) "snake"
        json_decode(base64_decode($data), true)['data'][3]['username']
        created => string (19) "2017-01-11 22:15:25"
        json_decode(base64_decode($data), true)['data'][3]['created']
        lastlog => string (19) "2017-02-06 01:45:46"
        json_decode(base64_decode($data), true)['data'][3]['lastlog']
        4 => array (3)
        json_decode(base64_decode($data), true)['data'][4]
        username => string (5) "crane"
        json_decode(base64_decode($data), true)['data'][4]['username']
        created => string (19) "2017-01-09 22:28:34"
        json_decode(base64_decode($data), true)['data'][4]['created']
        lastlog => string (19) "2017-01-22 00:12:26"
        json_decode(base64_decode($data), true)['data'][4]['lastlog']
        5 => array (3)
        json_decode(base64_decode($data), true)['data'][5]
        username => string (5) "panda"
        json_decode(base64_decode($data), true)['data'][5]['username']
        created => string (19) "2017-01-14 13:20:40"
        json_decode(base64_decode($data), true)['data'][5]['created']
        lastlog => string (19) "2017-01-27 23:14:40"
        json_decode(base64_decode($data), true)['data'][5]['lastlog']
    • {"color":"rgba(255, 255, 0, 0.5)","data":[{"username":"monkey","created":"2017-01-25 22:24:08","lastlog":"2017-01-28 14:49:51"},{"username":"tiger","created":"2017-01-03 11:40:50","lastlog":"2017-01-09 17:44:48"},{"username":"mantis","created":"2017-01-03 12:19:48","lastlog":"2017-01-10 14:46:51"},{"username":"snake","created":"2017-01-11 22:15:25","lastlog":"2017-02-06 01:45:46"},{"username":"crane","created":"2017-01-09 22:28:34","lastlog":"2017-01-22 00:12:26"},{"username":"panda","created":"2017-01-14 13:20:40","lastlog":"2017-01-27 23:14:40"}]}
      
  • eyJjb2xvciI6InJnYmEoMjU1LCAyNTUsIDAsIDAuNSkiLCJkYXRhIjpbeyJ1c2VybmFtZSI6Im1vbmtleSIsImNyZWF0ZWQiOiIyMDE3LTAxLTI1IDIyOjI0OjA4IiwibGFzdGxvZyI6IjIwMTctMDEtMjggMTQ6NDk6NTEifSx7InVzZXJuYW1lIjoidGlnZXIiLCJjcmVhdGVkIjoiMjAxNy0wMS0wMyAxMTo0MDo1MCIsImxhc3Rsb2ciOiIyMDE3LTAxLTA5IDE3OjQ0OjQ4In0seyJ1c2VybmFtZSI6Im1hbnRpcyIsImNyZWF0ZWQiOiIyMDE3LTAxLTAzIDEyOjE5OjQ4IiwibGFzdGxvZyI6IjIwMTctMDEtMTAgMTQ6NDY6NTEifSx7InVzZXJuYW1lIjoic25ha2UiLCJjcmVhdGVkIjoiMjAxNy0wMS0xMSAyMjoxNToyNSIsImxhc3Rsb2ciOiIyMDE3LTAyLTA2IDAxOjQ1OjQ2In0seyJ1c2VybmFtZSI6ImNyYW5lIiwiY3JlYXRlZCI6IjIwMTctMDEtMDkgMjI6Mjg6MzQiLCJsYXN0bG9nIjoiMjAxNy0wMS0yMiAwMDoxMjoyNiJ9LHsidXNlcm5hbWUiOiJwYW5kYSIsImNyZWF0ZWQiOiIyMDE3LTAxLTE0IDEzOjIwOjQwIiwibGFzdGxvZyI6IjIwMTctMDEtMjcgMjM6MTQ6NDAifV19
    
$object MysteriousObject#2 (2)
  • Properties (2)
  • Methods (1)
  • Static properties (1)

Letโ€™s take a look at this data with Kint

  • Click anywhere on the bar to unfold it
  • Double click + to unfold all children
  • Press d to toggle keyboard navigation.
  • Press a or the ๐Ÿ‘ Image
    icon on the right to see the access path to get at a piece of data.
  • Press s or the ๐Ÿ‘ Image
    icon on the right to open a live search.
  • Press f or the ๐Ÿ‘ Image
    icon on the right to move the dump to a docked folder.
  • Change tabs to see different views of data.
  • You can sort tables of data by clicking on the headers.

  • Kint automatically detects, unpacks, and parses common formats like XML, base64, and JSON
  • Detects common patterns like colors, filenames, tables, and timestamps and displays extra information about them
  • Provides the user with the exact piece of code they need to access some information nested deep in the hierarchy

Tips & Tricks

  • You can set Kint::$enabled_mode = false; to turn off output (For example, in production)
  • You can set nonces for CSP environments:
    • Kint\Renderer\AbstractRenderer::$js_nonce
    • Kint\Renderer\AbstractRenderer::$css_nonce
  • There are a couple of real-time modifiers you can use:
    • +d($var) will disregard depth level limits and output everything
      Careful, this can hang your browser on extremely large objects!
    • !d($var) will expand the output automatically
    • ~d($var) this call will output in plain text format
    • -d($var) will attempt to ob_clean the previous output and flush after printing
  • Add heavy classes to the blacklist to improve performance:
    Kint\Parser\BlacklistPlugin::$shallow_blacklist[] = SomeLargeClass::class;
  • To change display theme, use Kint\Renderer\RichRenderer::$theme = 'theme.css';. You can pass the absolute path to a CSS file, or use one of the built in themes:
    • original.css (default)
    • solarized.css
    • solarized-dark.css
    • aante-light.css
    • aante-dark.css
  • You can install kint-helpers for more shortcuts and kint-twig for twig integration

Advanced usage ยป