概述
Kint是一个类似于var_dump()
的PHP变量调试工具,但提供了更多高级功能,如键盘控制、搜索、访问路径提示和自动数据解析。支持JSON结构的展开和搜索,提供访问特定字段所需的代码片段。
安装
代码语言:javascript复制composer require kint-php/kint --dev
使用
简单打印
代码语言:javascript复制<?php
/**
* @desc 简单使用
* @author Tinywan(ShaoBo Wan)
*/
declare(strict_types=1);
require '../vendor/autoload.php';
d('开源技术小栈');
打印输出
打印全局变量
代码语言:javascript复制Kint::dump($GLOBALS, $_SERVER);
打印输出
代码语言:javascript复制┌──────────────────────────────────────────────────────────────────────────────┐
│ $GLOBALS │
└──────────────────────────────────────────────────────────────────────────────┘
array (11) [
'_GET' => array (0) []
'_POST' => array (0) []
'_COOKIE' => array (0) []
'_FILES' => array (0) []
'argv' => array (1) [
0 => string (8) "kint.php"
]
'argc' => integer 1
'_ENV' => array (0) []
'_REQUEST' => array (0) []
'_SERVER' => array (28) [
'HOSTNAME' => string (12) "ca699f9ea97c"
'PHP_INI_DIR' => string (18) "/usr/local/etc/php"
'SHLVL' => string (1) "1"
'HOME' => string (5) "/root"
'OLDPWD' => string (21) "/var/www/webman-admin"
'PHP_LDFLAGS' => string (12) "-Wl,-O1 -pie"
'PHP_CFLAGS' => string (83) "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
'PHP_VERSION' => string (6) "7.4.27"
'COMPOSER_HOME' => string (13) "/tmp/composer"
'GPG_KEYS' => string (81) "42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312"
'PHP_CPPFLAGS' => string (83) "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
'PHP_ASC_URL' => string (55) "https://www.php.net/distributions/php-7.4.27.tar.xz.asc"
'PHP_URL' => string (51) "https://www.php.net/distributions/php-7.4.27.tar.xz"
'TERM' => string (5) "xterm"
'PATH' => string (60) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
'LD_PRELOAD' => string (36) "/usr/lib/preloadable_libiconv.so php"
'PHPIZE_DEPS' => string (78) "autoconf dpkg-dev dpkg file g gcc libc-dev make
pkgconf re2c"
'PWD' => string (29) "/var/www/webman-admin/runtime"
'PHP_SHA256' => string (64) "3f8b937310f155822752229c2c2feb8cc2621e25a728e7b94d0d74c128c43d0c"
'PHP_SELF' => string (8) "kint.php"
'SCRIPT_NAME' => string (8) "kint.php"
'SCRIPT_FILENAME' => string (8) "kint.php"
'PATH_TRANSLATED' => string (8) "kint.php"
'DOCUMENT_ROOT' => string (0) ""
'REQUEST_TIME_FLOAT' => double 1724682740.6123
'REQUEST_TIME' => integer 1724682740
'argv' => array (1) [
0 => string (8) "kint.php"
]
'argc' => integer 1
]
'GLOBALS' => array (11) RECURSION
'__composer_autoload_files' => array (26) [
'a4a119a56e50fbb293281d9a48007e0e' => boolean true
'6e3fae29631ef280660b3cdad06f25a8' => boolean true
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => boolean true
'60799491728b879e74601d83e38b2cad' => boolean true
'a1105708a18b76903365ca1c4aa61b02' => boolean true
'72579e7bd17821bb1321b87411366eae' => boolean true
'0d59ee240a4cd96ddbb4ff164fccea4d' => boolean true
'253c157292f75eb38082b5acb06f3f01' => boolean true
'c964ee0ededf28c96ebd9db5099ef910' => boolean true
'7b11c4dc42b3b3023073cb14e519683c' => boolean true
'320cde22f66dd4f5d3fd621d3e88b98f' => boolean true
'8825ede83f2f289127722d4e842cf7e8' => boolean true
'e69f7f6ee287b969198c3c9d6777bd38' => boolean true
'b6b991a57620e2fb6b2f66f03fe9ddc2' => boolean true
'9b552a3cc426e3287cc811caefa3cf53' => boolean true
'37a3dc5111fe8f707ab4c132ef1dbc62' => boolean true
'35fab96057f1bf5e7aba31a8a6d5fdde' => boolean true
'f88f8987adfe3f7cf9978fa9a9d148bc' => boolean true
'b33e3d135e5d9e47d845c576147bda89' => boolean true
'6b998e7ad3182c0d21d23780badfa07b' => boolean true
'ef65a1626449d89d0811cf9befce46f0' => boolean true
'3917c79c5052b270641b5a200963dbc2' => boolean true
'dd35ab9cf6f82e3605192322869933c8' => boolean true
'080a2f403a1656ccb2331e10184e7f3b' => boolean true
'8c783b3a3de2f6d9177022b5ccdcc841' => boolean true
'da5b71a9ad8465d48da441e2f36823b6' => boolean true
]
]
┌──────────────────────────────────────────────────────────────────────────────┐
│ $_SERVER │
└──────────────────────────────────────────────────────────────────────────────┘
array (28) [
'HOSTNAME' => string (12) "ca699f9ea97c"
'PHP_INI_DIR' => string (18) "/usr/local/etc/php"
'SHLVL' => string (1) "1"
'HOME' => string (5) "/root"
'OLDPWD' => string (21) "/var/www/webman-admin"
'PHP_LDFLAGS' => string (12) "-Wl,-O1 -pie"
'PHP_CFLAGS' => string (83) "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
'PHP_VERSION' => string (6) "7.4.27"
'COMPOSER_HOME' => string (13) "/tmp/composer"
'GPG_KEYS' => string (81) "42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312"
'PHP_CPPFLAGS' => string (83) "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
'PHP_ASC_URL' => string (55) "https://www.php.net/distributions/php-7.4.27.tar.xz.asc"
'PHP_URL' => string (51) "https://www.php.net/distributions/php-7.4.27.tar.xz"
'TERM' => string (5) "xterm"
'PATH' => string (60) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
'LD_PRELOAD' => string (36) "/usr/lib/preloadable_libiconv.so php"
'PHPIZE_DEPS' => string (78) "autoconf dpkg-dev dpkg file g gcc libc-dev make
pkgconf re2c"
'PWD' => string (29) "/var/www/webman-admin/runtime"
'PHP_SHA256' => string (64) "3f8b937310f155822752229c2c2feb8cc2621e25a728e7b94d0d74c128c43d0c"
'PHP_SELF' => string (8) "kint.php"
'SCRIPT_NAME' => string (8) "kint.php"
'SCRIPT_FILENAME' => string (8) "kint.php"
'PATH_TRANSLATED' => string (8) "kint.php"
'DOCUMENT_ROOT' => string (0) ""
'REQUEST_TIME_FLOAT' => double 1724682740.6123
'REQUEST_TIME' => integer 1724682740
'argv' => array (1) [
0 => string (8) "kint.php"
]
'argc' => integer 1
]
════════════════════════════════════════════════════════════════════════════════
Called from <ROOT>/kint.php:10 [KintKint::dump()]
现场演示
你有一些数据,你需要从中获得更多的数据,但是你不知道数据是如何结构化的,直到你跟踪到里面。
代码语言:javascript复制$time = get_mysterious_value();
$data = get_mysterious_data();
$object = get_mysterious_object();
include 'kint.phar';
d($time, $data, $object);