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

Problems with displaying recursive objects/arrays in debug

 
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
mwhart
Smarty n00b


Joined: 16 Sep 2004
Posts: 2

PostPosted: Thu Sep 16, 2004 7:18 am    Post subject: Problems with displaying recursive objects/arrays in debug Reply with quote

G'day,

I'm not sure if this has been mentioned already, but if you have a recursive object or array passed into your Smarty template variables and you have debugging turned on, then Smarty will silently (at least on my setup) die when trying to display this variable in the debug console.

Now of course one can question whether one should be using recursive data structures - but I think Smarty should gracefully fail in this case (as PHP's var_export does for example) - in this case I'm using PEAR's FormBuilder and the FormBuilder object has references to itself for callback purposes (I'm going to write to them to change this).

Here's a small change that can stop this from happening (in plugins/modifier.debug_print_var.php):

Code:

function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
    if ($depth > 100) {
        trigger_error("Nesting level too deep - recursive dependency?", E_USER_ERROR);
    }

    // ... rest of function here
}


Of course the depth limit is fairly arbitrary and could even be set as a Smarty config variable (or possibly use whatever PHP uses).

Hope this is helpful to some people and that it can make it into the next release.

Cheers,

Michael
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Sep 16, 2004 8:46 am    Post subject: Reply with quote

this was already discussed here: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1426

i doubt it will be fixed.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mwhart
Smarty n00b


Joined: 16 Sep 2004
Posts: 2

PostPosted: Fri Sep 17, 2004 7:00 am    Post subject: Reply with quote

I don't see anything in that thread that indicates that it shouldn't be fixed.

I don't see why providing a depth limitation would be a problem - it could be quite a large value, and if someone really did want to change it then there could be an option.

Again, the var_export function in PHP dies when it reaches a certain level of depth, so why not just use the same functionality? It took me quite a few hours to track down the source of the browser's "Document contains no data" messages and absolutely nothing was logged, even with the error level set to E_ALL, so I really think this would help a lot more people than it would hinder - especially when using data structures that are not their own (it turns out it was the error backtrace in a PEAR_Error object that was recursing).

Is there a good reason not to have a depth limit?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Sep 17, 2004 7:28 am    Post subject: Reply with quote

In the other thread Stas says: "I think it's not good idea use depth limitation."
If that is not a pretty good reason, to not have a depth limit, then i don't know.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Sep 17, 2004 4:13 pm    Post subject: Reply with quote

I actually don't see why enabling a depth limit as a bailout is "bad". The main things I can think of is that it may not work (your script may consume to much ram, for example) and worse, that it does not let the developer know that they are facing a recursion issue. Without a way to determine references, the solution is open; in that case, a compromise like depth limiting may be useful to protect from unforseen issues, particularly during debuging.

Still, it is laughable that this is being triggered in a contained PEAR_Error object! Is it really necessary to include these objects in the template var space? As a rule, I'd say that application level objects have no business being reachable by the template. Still, that's not the point -- the point is that when you are debugging, you don't want your debug tools to fail!
Back to top
View user's profile Send private message
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