smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.24k stars 705 forks source link

Compilation error ? #917

Open lkppo opened 9 months ago

lkppo commented 9 months ago

Hello,

I had difficulty identifying a problem in a template. After reading the documentation I wonder if the behavior is normal or faulty.

$WXO_PRODUCT_CROSS and $WXO_PRODUCT_UP both have the value "".

The following code should not produce HTML output but it does. My error is a missing $ in the first condition.

            {if isset($WXO_PRODUCT_CROSS) && WXO_PRODUCT_CROSS ne ''}
                {if isset($WXO_PRODUCT_CROSS) && $WXO_PRODUCT_CROSS ne ''}
                <a href="#tab-articles-complementaires">{t}Additional articles{/t}</a>
                {/if}
                {if isset($WXO_PRODUCT_UP) && $WXO_PRODUCT_UP ne ''}
                <a href="#tab-articles-similaires">{t}Similar articles{/t}</a
                {/if}

                {$WXO_PRODUCT_CROSS}
            {/if}

The resulting code compiled by Smarty is:

<?php if ((isset($_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value)) && 'WXO_PRODUCT_CROSS' != '') {?>

instead of

<?php if ((isset($_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value)) && $_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value != '') {?>

Is it normal for "WXO_PRODUCT_CROSS" to be interpreted as a string instead of causing a compilation error?

wisskid commented 9 months ago

Interesting. This looks like the PHP bareword behavior that has been removed in php8.0. I never noticed it in Smarty before. Will have to test first. What smarty version and what php version are you using?

lkppo commented 9 months ago

I use PHP 8.0.1 and Smarty 3.1.48.