mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
enhance reporting precision of debug_print_var modifier
see: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=9281 thanks to cybot from the forums
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
|||||||
|
- enhance reporting precision of debug_print_var modifier (cybot, boots)
|
||||||
- make html_select_date work consistently with 0000-00-00 00:00:00 and
|
- make html_select_date work consistently with 0000-00-00 00:00:00 and
|
||||||
0000-00-00 inputs (cybot, boots)
|
0000-00-00 inputs (cybot, boots)
|
||||||
- fix wrong handling of insert's name attribute. (messju)
|
- fix wrong handling of insert's name attribute. (messju)
|
||||||
|
@@ -22,33 +22,64 @@
|
|||||||
*/
|
*/
|
||||||
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||||
{
|
{
|
||||||
$_replace = array("\n"=>'<i>\n</i>', "\r"=>'<i>\r</i>', "\t"=>'<i>\t</i>');
|
$_replace = array(
|
||||||
if (is_array($var)) {
|
"\n" => '<i>\n</i>',
|
||||||
$results = "<b>Array (".count($var).")</b>";
|
"\r" => '<i>\r</i>',
|
||||||
foreach ($var as $curr_key => $curr_val) {
|
"\t" => '<i>\t</i>'
|
||||||
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
|
);
|
||||||
$results .= "<br>".str_repeat(' ', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> => $return";
|
|
||||||
}
|
switch (gettype($var)) {
|
||||||
} else if (is_object($var)) {
|
case 'array' :
|
||||||
$object_vars = get_object_vars($var);
|
$results = '<b>Array (' . count($var) . ')</b>';
|
||||||
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
|
foreach ($var as $curr_key => $curr_val) {
|
||||||
foreach ($object_vars as $curr_key => $curr_val) {
|
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||||
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
|
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
||||||
$results .= "<br>".str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
|
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||||
}
|
}
|
||||||
} else if (is_resource($var)) {
|
break;
|
||||||
$results = '<i>'.(string)$var.'</i>';
|
case 'object' :
|
||||||
} else if (empty($var) && $var != "0") {
|
$object_vars = get_object_vars($var);
|
||||||
$results = '<i>empty</i>';
|
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
||||||
} else {
|
foreach ($object_vars as $curr_key => $curr_val) {
|
||||||
if (strlen($var) > $length ) {
|
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||||
$results = substr($var, 0, $length-3).'...';
|
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
||||||
} else {
|
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||||
$results = $var;
|
}
|
||||||
}
|
break;
|
||||||
$results = htmlspecialchars($results);
|
case 'boolean' :
|
||||||
$results = strtr($results, $_replace);
|
case 'NULL' :
|
||||||
|
case 'resource' :
|
||||||
|
if (true === $var) {
|
||||||
|
$results = 'true';
|
||||||
|
} elseif (false === $var) {
|
||||||
|
$results = 'false';
|
||||||
|
} elseif (null === $var) {
|
||||||
|
$results = 'null';
|
||||||
|
} else {
|
||||||
|
$results = htmlspecialchars((string) $var);
|
||||||
|
}
|
||||||
|
$results = '<i>' . $results . '</i>';
|
||||||
|
break;
|
||||||
|
case 'integer' :
|
||||||
|
case 'float' :
|
||||||
|
$results = htmlspecialchars((string) $var);
|
||||||
|
break;
|
||||||
|
case 'string' :
|
||||||
|
$results = strtr($var, $_replace);
|
||||||
|
if (strlen($var) > $length ) {
|
||||||
|
$results = substr($var, 0, $length - 3) . '...';
|
||||||
|
}
|
||||||
|
$results = htmlspecialchars('"' . $results . '"');
|
||||||
|
break;
|
||||||
|
case 'unknown type' :
|
||||||
|
default :
|
||||||
|
$results = strtr((string) $var, $_replace);
|
||||||
|
if (strlen($results) > $length ) {
|
||||||
|
$results = substr($results, 0, $length - 3) . '...';
|
||||||
|
}
|
||||||
|
$results = htmlspecialchars($results);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user