Re: [SMARTY-DEV] Debug console problem (and solution) - objects handled incorrectly
| From: | Simon Willison | Date: | Tue, 23 Jul 2002 23:28:36 +0000 |
| Subject: | Re: [SMARTY-DEV] Debug console problem (and solution) - objects handled incorrectly | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-219@lists.php.net to get a copy of this message | ||
At 00:26 24/07/2002 +0100, Simon Willison wrote:
I recently ran in to a problem with the Smarty debugging console falling over when faced with a template that has objects assigned as variables. I've updated the modifier.debug_print_var.php to allow for objects as well as arrays, and the replacement file is attached to this email.It looks like something stripped the attachment along the way, so I've pasted the file in to /this/ email :) ============ <?php /* * Smarty plugin * -------------------------------------------------------------
* Type: modifier * Name: debug_print_var* Purpose: formats variable contents for display in the console * ------------------------------------------------------------- */ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) {
if (is_array($var)) {
$results = "<b>Array (".count($var).")</b>";
foreach ($var as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1);
$results .= '<br>\r'.str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
}
return $results;
} else if (is_object($var)) {
$object_vars = get_object_vars($var);
$results = "<b>Object (".count($object_vars).")</b>";
foreach ($object_vars as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1);
$results .= '<br>\r'.str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
}
return $results;
} else {
if (empty($var) && $var != "0") {
return '<i>empty</i>';
}
if (strlen($var) > $length ) {
$results = substr($var, 0, $length-3).'...';
} else {
$results = $var;
}
$results = preg_replace("![\r\t\n]!", " ", $results);
$results = htmlspecialchars(htmlspecialchars($results));
return $results;
}
}
/* vim: set expandtab: */
?>