Replies: 8 comments 42 replies
-
Thank you for starting this as a discussion! If I understand correctly, then the main reasons are:
Both are valid points, but I do afraid that this solution raises more problems that it solves. For example, when this update will be implemented, then it will mean that there will be even more complains from users that now Smarty is not working at all (and this time it will be Smarty, not PHP version change). Ok, there is a workaround, but it means that every developer in the world will have to find this workaround and copypaste it to the code. Is it worth it? Also, I am not sure that the main behavior is that only limited list of functions is allowed. During the years (I still have my project where I have used Smarty around 2010) , developers are got used to be able to use native/userland functions directly in the Smarty code. Is it good/bad ? Hard to say. Also, it will be quite hard to find all functions used, especially for the old, large codebase, which means that wildcard solution would be de facto standard for the old code. Other platformsI have checked Laravel Blade, and looks it actually supports native/userland functions out of the box. For example: Looks like Twig does not natively support it, correct me if I am wrong. Proposed solutionShould this new behavior be optional, similar how This solution is kinda like implementing "dirty solution" you have above, but inside Smarty itself. This will simplify life of many developers in the world. |
Beta Was this translation helpful? Give feedback.
-
First af all thanx for the hard work, we use smarty since the first release and followed the development and sometimes contribuited too (before the current team take the lead). This i think is a major issue, we use smarty in around 200 projects. This huge changes broke completely every single application so we should stay on old version since we cannot use 3-4 weeks time following every single change and also making single modifier for every single php function. We will wait some time but if retro-compatibility disappear we should search for a new library or develop our own or maybe fork the latest working release, and i think many will do same.. Sorry to have bothered with this reflection.. |
Beta Was this translation helpful? Give feedback.
-
Wow, this is huge! |
Beta Was this translation helpful? Give feedback.
-
Why? What change in PHP 8 prohibits the use of this mechanism? I don’t see any prohibitions in the changelog: |
Beta Was this translation helpful? Give feedback.
-
Is there a similar solution for smarty 4? |
Beta Was this translation helpful? Give feedback.
-
I have two related questions. The Smarty 5 documentation still show the |
Beta Was this translation helpful? Give feedback.
-
Hi @wisskid As per discussion #967, Smarty 4.5 has introduced deprecation notices to warn users about the usage of unregistered callables in templates. To prevent these warnings from cluttering the logs, we've implemented a fix that suppresses these deprecation notices by utilizing the muteUndefinedOrNullWarnings function for Smarty 4.5. This change ensures that deprecated notices for unregistered callables are properly handled, preventing unnecessary interruptions Please review PR #1067 for the same. |
Beta Was this translation helpful? Give feedback.
-
Hi, I want to add our frustration to this too. We have 550+ sites (through some no longer active) that we've been slowly upgrading from Smarty 3 as needed. I get the concerns raised by the maintainers, but I think it needs to be easier to not have to deal with these deprecation notices. As a basic example, we have a function called {if empty_date($date)}
(no date)
{/if} So, let's say we have a list of these functions: $safe = ['empty_date', 'ltrim', 'whatever']; // there's a bunch, but as an example What DOESN'T work: $security = new \Smarty_Security($smarty);
$security->php_functions = $safe;
$smarty->enableSecurity($security); Why doesn't that work? As an aside, This DOESN'T work either: foreach ($safe as $function)
{
if (!function_exists($function))
continue;
$smarty->registerPlugin(\Smarty::PLUGIN_FUNCTION, $function, $function);
} Why doesn't that work? So after some not inconsiderable frustration and digging through the Smarty code, we found that this DOES work: foreach ($safe as $function)
{
if (!function_exists($function))
continue;
$smarty->registerPlugin(\Smarty::PLUGIN_MODIFIER, $function, $function);
} Why? smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php Lines 658 to 666 in c11676e Why does registering these I get that if we were using them like Of the reasons given for this change, there is still no justification for this amount of BC and frustration, and no reason why there shouldn't be a simple AND DOCUMENTED method of whitelisting functions. $smart->registerFunctions(['empty_date', 'ltrim', 'whatever']); That's all it should take. We had a similar issue with static classes, but it could be solved with |
Beta Was this translation helpful? Give feedback.
-
Starting from Smarty v5.0.0, it is no longer possible to use unregistereded callables (such as PHP functions) in templates as modifiers or as functions in expressions. To use the callables, you need to register them first. Preferably in an Extension or in the old-fashioned way by using
$smarty->registerPlugin("modifier", "strrev", "strrev")
.To assist users in making the transition to Smarty 5, Smarty 4.5 has introduced deprecation notices to warn users when they are using unregistereded callables in their templates. Deprecation notices are not errors and they don't mean your code is broken (yet). They are helpful to assist you in making the transition to Smarty 5, should you ever wish to do so. Read more about dealing with deprecations if you want to learn more.
But why?
Supporting changes in PHP
Some people have expressed frustrations about the decision to drop support for unregistered callables and wonder why Smarty is doing this. This is discussed in length in Issues and PRs, such as #813. To summarize: many users have filed bug reports to "fix" compatibility issues in modifiers that were never part of the Smarty language. For example: in PHP's join or implode it used to be possible to switch separator and array. When using
join
orimplode
as a modifier, it makes sense to switch them for readability. However, since PHP8.0 this is no longer allowed. Is this a bug in Smarty now?Security and separation of concerns
Not relevant for everybody, but supporting each and every callable can be a nightmare when you need a strict separation between front-end developers (possibly even anonymous users) and PHP-developers. Allowing callables means you can do funny stuff like:
And yes, Smarty has security features that are meant to block stuff like this, but we felt it was better to stop this at the beginning.
Stability
One of the goals of Smarty is to provide a stable interface. This means we try to have automated testing for every language element for every supported version of PHP. If we do not somehow limit the amount of functions template authors can use, this is impossible.
Other template engines, such as Twig for example, follow the same principle.
A dirty fix
If writing a proper Extension feels as too much work, we have an easy fix for Smarty 5.
and
It's not pretty, but at least this makes it rather clear who is responsible for supporting the callables.
Beta Was this translation helpful? Give feedback.
All reactions