Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch recursion #91

Closed
andyburton opened this issue Sep 18, 2015 · 3 comments
Closed

Fetch recursion #91

andyburton opened this issue Sep 18, 2015 · 3 comments

Comments

@andyburton
Copy link

Calling fetch() on the $tpl argument passed to a function plugin is causing recursion after updating from 3.1.21 to 3.1.27

Previously this would run happily but since the update it is causing a seg fault due to recursion!

function smarty_function_messages ($params, &$tpl)
{
    $messages = null;
    foreach (Message::get() as $message) {
        $tpl->assign ('message', $message);
        $messages .= $tpl->fetch ('message.tpl');
    }
    return $messages;
}

The call to fetch now appears to re-render the template already defined on $tpl resulting in the original template containing the function call to {messages} being re-executed and hence recursion.

I've not delved too far into the Smarty code but copy/pasting bits from the fetch function into this does get things working without recursion -

function smarty_function_messages ($params, &$tpl)
{
    $messages = null;
    foreach (Message::get() as $message) {
        $newTpl = $tpl->createTemplate('message.tpl');
        $newTpl->caching = $tpl->caching;
        $newTpl->assign ('message', $message);
        $messages .= $newTpl->render();
    }
    return $messages;
}
@uwetews
Copy link
Contributor

uwetews commented Sep 18, 2015

Its a bug. I will try to fix this asap

@uwetews
Copy link
Contributor

uwetews commented Sep 18, 2015

Same as here #70.
Its already covered in the master branch. However some work is in progress there for the 3.1.28 release.

Looking at your code the following should have even better performance as the original one

function smarty_function_messages ($params, &$tpl)
{
    $messages = null;
    $newTpl = $tpl->createTemplate('message.tpl');
    $newTpl->caching = $tpl->caching;
    foreach (Message::get() as $message) {
        $newTpl->assign ('message', $message);
        $messages .= $newTpl->render();
    }
    return $messages;
}

No need to recreate $newTpl in the loop.

@uwetews uwetews closed this as completed Sep 18, 2015
@uwetews uwetews reopened this Sep 18, 2015
@andyburton
Copy link
Author

Thanks for looking into this :)

The example code i provided is massively slimmed down to demonstrate the bug - but yes i appreciate you do not need to re-create the same template each time.

@uwetews uwetews closed this as completed Dec 4, 2015
think-mcunanan pushed a commit to think-mcunanan/smarty that referenced this issue Mar 22, 2023
Merge release-2.0.10 into master branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants