|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mwhart Smarty n00b
Joined: 16 Sep 2004 Posts: 2
|
Posted: Thu Sep 16, 2004 7:18 am Post subject: Problems with displaying recursive objects/arrays in debug |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
mwhart Smarty n00b
Joined: 16 Sep 2004 Posts: 2
|
Posted: Fri Sep 17, 2004 7:00 am Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Sep 17, 2004 7:28 am Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Sep 17, 2004 4:13 pm Post subject: |
|
|
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 |
|
|
|
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
|