rav*_*ren 67
在问了这一整年的时间和劳动之后,我终于开源了我的版本var_dump,Kint.在项目页面中或直接在github中阅读它.
这是一个截图:
对不起插头:)
编辑:我想提醒评论者,这不是一个支持论坛,如果您遇到问题/想要一个功能,请提出问题.支持请求评论将被标记为删除.
Pas*_*TIN 44
我上首选的是var_dump
功能,如Xdebug扩展提供:刚安装扩展(容易,无论是在Windows和Linux) ,并var_dump
得到一个更好的输出:
并快速截图:
而且,当然,Xdebug带来了许多其他有用的东西,比如远程调试(例如PHP应用程序的图形调试,例如Eclipse PDT),分析,......
Gui*_*ips 26
这是我的,我使用内联,非常有用:
$pretty = function($v='',$c=" ",$in=-1,$k=null)use(&$pretty){$r='';if(in_array(gettype($v),array('object','array'))){$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").'<br>';foreach($v as $sk=>$vl){$r.=$pretty($vl,$c,$in+1,$sk).'<br>';}}else{$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").(is_null($v)?'<NULL>':"<strong>$v</strong>");}return$r;};
echo $pretty($some_variable);
Run Code Online (Sandbox Code Playgroud)
我的(部分)解决方案是简单地添加这样的功能(使用谷歌浏览器):
<?
function console_dump($value)
{
?>
<script>
console.log(<? echo json_encode($value); ?>);
</script>
<?
}
?>
Run Code Online (Sandbox Code Playgroud)
按Ctrl + Shift + J(打开控制台),您可以在那里找到JSON结构.对于JSON应答程序的漂亮打印更有用.
我用的一个完整的例子......
<pre>
<?php
//*********** Set up some sample data
$obj = new stdClass;
$obj->a=123;
$obj->pl=44;
$obj->l=array(31,32);
$options = array(
'Orchestra'=>array(1=>'Strings', 8=>'Brass', 9=>$obj, 3=>'Woodwind', 16=>'Percussion'),
2=>'Car',
4=>'Bus',
'TV'=>array(21=>'Only Fools', 215=>'Brass Eye', 23=>'Vic Bob',44=>null, 89=>false));
//*********** Define the function
function dump($data, $indent=0) {
$retval = '';
$prefix=\str_repeat(' | ', $indent);
if (\is_numeric($data)) $retval.= "Number: $data";
elseif (\is_string($data)) $retval.= "String: '$data'";
elseif (\is_null($data)) $retval.= "NULL";
elseif ($data===true) $retval.= "TRUE";
elseif ($data===false) $retval.= "FALSE";
elseif (is_array($data)) {
$retval.= "Array (".count($data).')';
$indent++;
foreach($data AS $key => $value) {
$retval.= "\n$prefix [$key] = ";
$retval.= dump($value, $indent);
}
}
elseif (is_object($data)) {
$retval.= "Object (".get_class($data).")";
$indent++;
foreach($data AS $key => $value) {
$retval.= "\n$prefix $key -> ";
$retval.= dump($value, $indent);
}
}
return $retval;
}
//*********** Dump the data
echo dump($options);
?>
</pre>
Run Code Online (Sandbox Code Playgroud)
输出......
Array (4)
[Orchestra] = Array (5)
| [1] = String: 'Strings'
| [8] = String: 'Brass'
| [9] = Object (stdClass)
| | a -> Number: 123
| | pl -> Number: 44
| | l -> Array (2)
| | | [0] = Number: 31
| | | [1] = Number: 32
| [3] = String: 'Woodwind'
| [16] = String: 'Percussion'
[2] = String: 'Car'
[4] = String: 'Bus'
[TV] = Array (5)
| [21] = String: 'Only Fools'
| [215] = String: 'Brass Eye'
| [23] = String: 'Vic Bob'
| [44] = NULL
| [89] = FALSE
Run Code Online (Sandbox Code Playgroud)
小智 6
这是我的:
class sbwDebug
{
public static function varToHtml($var = '', $key = '')
{
$type = gettype($var);
$result = '';
if (in_array($type, ['object', 'array'])) {
$result .= '
<table class="debug-table">
<tr>
<td class="debug-key-cell"><b>' . $key . '</b><br/>Type: ' . $type . '<br/>Length: ' . count($var) . '</td>
<td class="debug-value-cell">';
foreach ($var as $akey => $val) {
$result .= sbwDebug::varToHtml($val, $akey);
}
$result .= '</td></tr></table>';
} else {
$result .= '<div class="debug-item"><span class="debug-label">' . $key . ' (' . $type . '): </span><span class="debug-value">' . $var . '</span></div>';
}
return $result;
}
}
Run Code Online (Sandbox Code Playgroud)
风格:
table.debug-table {
padding: 0;
margin: 0;
font-family: arial,tahoma,helvetica,sans-serif;
font-size: 11px;
}
td.debug-key-cell {
vertical-align: top;
padding: 3px;
border: 1px solid #AAAAAA;
}
td.debug-value-cell {
vertical-align: top;
padding: 3px;
border: 1px solid #AAAAAA;
}
div.debug-item {
border-bottom: 1px dotted #AAAAAA;
}
span.debug-label {
font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)
我最近开发了一个免费的chrome扩展(正在进行中),以便美化我的var转储,没有库,没有预标记,也没有安装到每个应用程序.全部使用JavaScript和regEx完成.你所要做的就是安装扩展程序和你的好处.我也在开发Firefox版本.这是GitHub页面.我希望很快就能在chrome和firefox网站上提供它!
https://github.com/alexnaspo/var_dumpling
这是一个示例输出: