Skip to content

using php function time in template should display a warning#1115

Open
shadowwa wants to merge 1 commit intosmarty-php:support/4from
shadowwa:time-should-warn-deprecated
Open

using php function time in template should display a warning#1115
shadowwa wants to merge 1 commit intosmarty-php:support/4from
shadowwa:time-should-warn-deprecated

Conversation

@shadowwa
Copy link
Copy Markdown
Contributor

Fixes #1114

@wisskid
Copy link
Copy Markdown
Member

wisskid commented Mar 17, 2025

How about libs/sysplugins/smarty_internal_templatecompilerbase.php:662:

                    if (
                        !$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
                        && !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
                        && !in_array($name, ['time', 'join', 'is_array', 'in_array', 'count'])
                    ) {
                        trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
                            'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                            'a custom modifier.', E_USER_DEPRECATED);
                    }

@shadowwa
Copy link
Copy Markdown
Contributor Author

shadowwa commented Mar 17, 2025

I don't get it, this is the modification I proposed.

Edit: did you mean libs/sysplugins/smarty_internal_compile_private_modifier.php:112 ?:

                                if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
                                    trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
                                        'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                                        'a custom modifier.', E_USER_DEPRECATED);
                                }

To be honest I don't know what is the use of this part of code.
Not only it does not change the behaviour of displaying a warning or not for time() but it contrary to libs/sysplugins/smarty_internal_templatecompilerbase.php:662 it does not check against 'count' and currently usage of {count($var)} or {$var|count} in template work correctly without deprecation warnings

@wisskid
Copy link
Copy Markdown
Member

wisskid commented Mar 17, 2025

Sorry, my bad. Copied the wrong reference. I meant to reference this: libs/sysplugins/smarty_internal_compile_private_modifier.php:112:

if (!is_object($compiler->smarty->security_policy)
                                || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
                            ) {
                                if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
                                    trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
                                        'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                                        'a custom modifier.', E_USER_DEPRECATED);
                                }
                                $output = "{$modifier}({$params})";
                            }

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

Successfully merging this pull request may close these issues.

2 participants