-
Notifications
You must be signed in to change notification settings - Fork 715
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
smarty.const wrongly evaluated for usage with comparison operators #613
Comments
see libs/sysplugins/smarty_internal_compile_private_special_variable.php |
relates also logical operators #609 |
Correct |
I think this is the main thing to focus on! And I had wondered why nobody came up with it yet. The #605 issue is just pointing wrong since PHP 7.4+ was getting more strict regarding constants. Smarty is not a layer to fix up things like this 818aa3c. Wrong usage of constant is just wrong usage and should not get "fixed" by an interpreter. IMHO, the right Smarty usage for null Constants, besides Constants not being meant to be used like dynamic assigned VARIABLES and in conditional structures like if / else, and when you are not sure it is defined at all, is this: {$smarty.const.TEST|default:''} or {$smarty.const.TEST|default:$smarty.const.ANOTHER} So regarding all mentioned examples I would recommend to assign real variables instead and remove this misleading fix 818aa3c. that indeed would need the parenthesis fixup like already mentioned. |
@ophian Backwards compatability is also a thing you know. |
@harm-smits I don't see what you mean by this. Backward compat of wrong usage? |
Seeing as Smarty is still compatible with PHP 5.2, I'd say backwards compatability (even of wrong usage), is essential. You don't just change behaviour for no apparant reason. This instead should be done for smarty version 4. Changing error levels is something that is considered a major change after all. |
I did not talk about changing error levels. This is a second thing in the commit and is done for unit tests only.
In this case you could not use PHP 7/8, since they do. 😉 |
What are you on? You just stated, you want undefined consts, to now cause a 'Notice' of some sorts, which is per definition changing error levels and previous behaviour. Also insinuating that different behaviour for different PHP versions should be a thing is just not okay. This causes inconsistency and will only cause confusion for those using smarty and expecting it to at least behave the same on different PHP versions. |
Well Yes, and No, not really. I stated, that I want Smarty to behave like PHP. If the latter changes error/notice reporting for general improvement, for when someone uses code falsely, I would like to have this happen equally. The commit tries to fix this in my eyes. So it is more a matter of, if Smarty should be trying to be more smarter than the parent system it depends on, or not, ...even if "Smarty" and "Smart" do have the same wording root 😄 ...and we all like its easiness. This is nothing to get into conflicts. Its a position, and I can understand yours too. I just think having a Smarty defined ternary on constant defines will never show the cause and that something IS wrong, or even wrongly used, and which (as stated) could even in Smarty get an easy fix - if you get it into attention. I fixed a lot of old systems and templates because of things like this, so I know where I come from. So for my view it is more a call to the Devs to get their work done! Be precise and not lazy as PHP was in its younger days. Show your Smarty using Users how to do it right! Thats all. |
Prepared PR with fix #618. |
This refers to the current fixes for PHP 8 see #605
simple dummy example
somewhere in php
define('_THEME', 'light');
template
{if $smarty.const._THEME == 'dark'} dark mode selected {elseif $smarty.const._THEME == 'light'} light mode selected {/if}
expected output
light mode selected
but using current master with the PHP 8 fixes output is
dark mode selected
this happens due to generated php
see file attached
example.txt
ok, looks like the in #605 proposed change for constant handling was already built in
imo the way its done is wrong
and, and its seems to me that smarty should not be responsible for handling undefined constants
I think this should be done at the application layer in PHP or whatever
if an constant is not defined and the application developer knows that this can happen (should not) the developer is responsible to handle this situation
smarty should not hide this
The text was updated successfully, but these errors were encountered: