"Fatal error: Maximum function nesting level of '100' reached" with Smarty 3.1.16

115 views
Skip to first unread message

Fran Diéguez

unread,
Jan 13, 2014, 5:24:36 PM1/13/14
to smarty-d...@googlegroups.com
Hi all,

I have a weird problem that raises with Smarty 3.1.15 (included) upwards to dev-trunk with nested templates. Let me explain:

I want to render a multi-level menu and for that I have an array of 'MenuElement' objects, each object can have multiple 'MenuElement' objects as childs inside the MenuElement->submenu property. And I've been rendering them as a nested template.

I render the menu by passing the $menu variable, which contains an array with some MenuElement objects, to the next template:

# menus/new.tpl
{if isset($menu) && is_array($menu->items) && count($menu->items) > 0}
     {foreach from=$menu->items item=menuItem}
         {include file="menus/partials/_menu_item.tpl" menuItem=$menuItem}
     {/foreach}
{/if}

as you can see the previous template iterates over all the array elements and includes an external file which contains the next:

# menus/partials/_menu_item.tpl file contents
<li class="menuItem"  id="item_{$menuItem->pk_item}">
    <div>
        <span class="type">
            Menu element
        </span>
        <span class="menu-title">
            {$menuItem->title}
        </span>
    </div>
    {if count($menuItem->submenu) > 0}
    <ol>
        {foreach $menuItem->submenu as $subMenuItem}
               {include file="menus/partials/_menu_item.tpl" menuItem=$subMenuItem}
        {/foreach}
    </ol>
    {/if}
</li>

As you can see if a particular menu element has children in its ->submenu property it will include the same file to reiterate over the child.
So, here is the thing... Before 3.1.15 this approach have been working without any problem. But with newer versions this has stopped to work by raising a fatal error with "Fatal error: Maximum function nesting level of '100' reached"

Can you test it if you can reproduce it?

uwe.tews

unread,
Jan 13, 2014, 5:59:12 PM1/13/14
to smarty-d...@googlegroups.com
A couple of questions:

Does it occur when the templates must be compiled or when the page should be displayed?

What is the maximum nesting level of your menu?

What happens if you increase the maximum nesting level with ini_set lets say to 200?

Do you use template inheritance?

Did you use the $smarty->merge_compiled_includes = true; option?

I'm travelling until the weekend so I can't run tests until I have returned.

Regards Uwe

Fran Diéguez

unread,
Jan 13, 2014, 6:09:06 PM1/13/14
to smarty-d...@googlegroups.com
Sorry I had to provide more information about the issue:

For the record, I'm running PHP 5.5.7.




On Monday, January 13, 2014 11:59:12 PM UTC+1, uwe.tews wrote:
Does it occur when the templates must be compiled or when the page should be displayed?
 
- The error occurs when templates have to be compiled. If I compile the templates with 3.1.14 and after that I upgrade Smarty to 3.1.16 without cleaning the compiled templates everything works. 

What is the maximum nesting level of your menu?

What happens if you increase the maximum nesting level with ini_set lets say to 200?

The maximum nesting level of the menu is 2. That means the menu elements can only have one level of subelements. 
I have tested to increase the max nesting level to 200, 500, and 800 and continues to crash with all the previous values. So I can assume that this will still happens if I increase it more. 

Do you use template inheritance?

Yes I use template inheritance. Obviously I have summarized the templates that I've written in the previous message.
 
Did you use the $smarty->merge_compiled_includes = true; option?

Yes, I have tested with that property right now and the error persists. 

I'm travelling until the weekend so I can't run tests until I have returned.

Thanks for your help.

Regards. 

uwe.tews

unread,
Jan 18, 2014, 9:49:35 AM1/18/14
to smarty-d...@googlegroups.com

The fix is now in the SVN trunk and will later be included in Smarty 3.1.17

The compiler always did fail when template inheritance and recursive {include} have been used together.


Regards Uwe


Am Montag, 13. Januar 2014 23:24:36 UTC+1 schrieb Fran Diéguez:

Fran Dieguez

unread,
Jan 18, 2014, 10:44:14 AM1/18/14
to smarty-d...@googlegroups.com, uwe.tews
> --
> You received this message because you are subscribed to the Google
> Groups "Smarty Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to smarty-develop...@googlegroups.com.
> To post to this group, send email to smarty-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/smarty-developers.
> For more options, visit https://groups.google.com/groups/opt_out.

Thanks for your help.

When it is expected the next release?

uwe....@googlemail.com

unread,
Jan 18, 2014, 10:59:39 AM1/18/14
to smarty-d...@googlegroups.com
Fran

I would expect 3.1.17 latest for end of February. It depends always on the number and importance of fixes.
Let's see if other run into this problem. Could be that inheritance and recursive {include} is a rare constellation.

I'm still wondering why this problem did not occur already on earlier versions, because that code was not correct for long time.
I did made a major change in inheritance, so some flags might have been set now at a different time....

Anyway the solution was found quickly and the change was very easy.....

Thanks again for your input and sending your templates. It is always good to have a real test case.

All the best and always be smart(y). lol




-----Ursprüngliche Nachricht-----
Von: smarty-d...@googlegroups.com [mailto:smarty-d...@googlegroups.com] Im Auftrag von Fran Dieguez
Gesendet: Samstag, 18. Januar 2014 16:44
An: smarty-d...@googlegroups.com
Cc: uwe.tews
Betreff: Re: "Fatal error: Maximum function nesting level of '100' reached" with Smarty 3.1.16
Reply all
Reply to author
Forward
0 new messages