Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Bug in Debug (smarty_modifier_debug_print_var)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Stas
Smarty n00b


Joined: 18 Nov 2003
Posts: 2

PostPosted: Tue Nov 18, 2003 3:18 pm    Post subject: Bug in Debug (smarty_modifier_debug_print_var) Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 18, 2003 4:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Stas
Smarty n00b


Joined: 18 Nov 2003
Posts: 2

PostPosted: Wed Nov 19, 2003 8:29 am    Post subject: My easy solution Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Nov 19, 2003 5:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Nov 25, 2003 2:22 pm    Post subject: Reply with quote

@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
View user's profile Send private message Send e-mail Visit poster's website
nleippe
Smarty n00b


Joined: 11 Jan 2004
Posts: 1

PostPosted: Sun Jan 11, 2004 12:13 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun Jan 11, 2004 8:37 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP