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

registerFilter does not allow to use Anonymous functions(closures) #59

Closed
ildar-aim opened this issue Jun 18, 2015 · 5 comments
Closed

Comments

@ildar-aim
Copy link

The sample code is

    $tpl->registerFilter('output', function($source, $smarty){
        if ($smarty->smarty->isEvalTemplate($smarty->template_resource)) {
            return 'Test is passed.';
        } else {
            return 'Test is failed. Fix strpos in isEvalTemplate() method related to "eval:" string';
        }
    });

the possible fix is

-        if (!empty($template->smarty->registered_filters[$type])) {
+        if (isset($template->smarty->registered_filters[$type])) {

The function _get_filter_name returns wrong name for a closure
It results to
Warning: Illegal offset type to /lib/smarty3/sysplugins/smarty_internal_templatebase.php on line 699

callable1

callable2

PHP 5.3.29

@uwetews
Copy link
Contributor

uwetews commented Jun 19, 2015

Closure support is new added in the dev-master version.
It will be included in 3.1.28

Read also NEW_FEATURES.txt

@uwetews uwetews closed this as completed Jun 19, 2015
@ildar-aim
Copy link
Author

Thank you.

@ildar-aim
Copy link
Author

May be an issue with two or more closure's filters.

1)first call to registerFilter returns
registered_filters[$type]['closure'] = closure_obj1

2)second call to registerFilter overwrites the first filter
registered_filters[$type]['closure'] = closure_obj2

The problem code is not uniq index in the _getFilterName function

return 'closure';

@ildar-aim
Copy link
Author

Should I open a new ticket related to non-unique filter names ?

@uwetews
Copy link
Contributor

uwetews commented Jun 20, 2015

I updated NEW_FEATURES.txt to make it more clear.

If you register multiple closures use the new filter name parameter to assign unique filter names.

$smarty->registerFilter('pre', function($content) {return $content;}, 'name1');
$smarty->registerFilter('pre', function($content) {return $content;}, 'name2');

think-mcunanan pushed a commit to think-mcunanan/smarty that referenced this issue Mar 22, 2023
Merge release-2.0.7 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