View previous topic :: View next topic |
Author |
Message |
Stas Smarty n00b
Joined: 18 Nov 2003 Posts: 2
|
Posted: Tue Nov 18, 2003 3:18 pm Post subject: Bug in Debug (smarty_modifier_debug_print_var) |
|
|
Hello.
Some trouble with {debug}. When data structure contain recursion, function smarty_modifier_debug_print_var are going to recursion also.
function smarty_modifier_debug_print_var contain information about depth, but don't use it for limit recursion level. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Nov 18, 2003 4:24 pm Post subject: |
|
|
agreed. what would be a reasonable maximum value for $depth. and what should be printed if the maximum is reached?
greetings
messju |
|
Back to top |
|
Stas Smarty n00b
Joined: 18 Nov 2003 Posts: 2
|
Posted: Wed Nov 19, 2003 8:29 am Post subject: My easy solution |
|
|
I think it's not good idea use depth limitation. At first I want to save references for printed var, but PHP can't compare two references and this solution was wrong.
Now I'm change function smarty_modifier_debug_print_var :
Code: | function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
ob_start();
print "<pre>";
print_r($var);
print "</pre>";
$ret_str = ob_get_contents();
ob_end_clean();
$_replace = array("\t"=>' ');
return strtr($ret_str,$_replace);
} |
Maybe someone write code for parsing print_r() result and build pretty HTML code. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Nov 19, 2003 5:36 pm Post subject: |
|
|
parsing print_r's output sounds kludgy to me. if anybody has a nice solution for the problem i'm happy to fix add it to debug_print_var, though. i have no cycles to spare on this issue at the moment. i think the bug is rare and easy to work around (as you noted). i think 2.6.0-final shouldn't be delayed for a fix to this one.
greetings
messju
Last edited by messju on Mon Apr 25, 2005 10:39 am; edited 1 time in total |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Nov 25, 2003 2:22 pm Post subject: |
|
|
@Stas: i'd escape the print_r-ouput, just in case you have html-code in your template-vars.
something along this:
[php:1:c9158afba7]
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
$ret_str = "<pre>";
ob_start();
print_r($var);
$ret_str .= htmlspecialchars(ob_get_contents());
ob_end_clean();
$ret_str .= "</pre>";
$_replace = array("\t"=>' ');
return strtr($ret_str,$_replace);
}
[/php:1:c9158afba7]
greetings
messju |
|
Back to top |
|
nleippe Smarty n00b
Joined: 11 Jan 2004 Posts: 1
|
Posted: Sun Jan 11, 2004 12:13 am Post subject: |
|
|
Just pointing out that you don't need an ob with print_r().
Just use:
[php:1:cfc68e8972]$ret_str .= htmlspecialchars(print_r($var, true));[/php:1:cfc68e8972] |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Jan 11, 2004 8:37 am Post subject: |
|
|
nleippe wrote: | Just use:
[php:1:8e961574fc]$ret_str .= htmlspecialchars(print_r($var, true));[/php:1:8e961574fc] |
this works since 4.3.0. smarty claims to work with 4.0.6 and later. that's the reason for the output-buffering above. |
|
Back to top |
|
|