smarty-php / smarty

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

Warning should not be triggered when checking for isset() of unassigned variable and smarty->error_unassigned = true #1063

Open yurii-sio2 opened 2 months ago

yurii-sio2 commented 2 months ago

When trying to read from undefined/unassigned variable there is no warning triggered, because Smarty always converts any unassigned and null variables into an empty string.

These is the option $smarty->error_unassigned = true, it enables Warning about accessing an unassigned variable. But! This is not useful because it triggers Warning even when you check a variable with isset(...)

{if isset($variable)} - results in Warning when error_unassigned = true

IMO when checking a variable with isset() then it should not trigger a warning because you explicitly check for variable existence.

This is especially uncomfortable when you develop new big form and you don't know what variables you didn't pass yet.

Checked in Smarty version 5.3.1. Seems like current version also has this problem.

yurii-sio2 commented 2 months ago

May somebody react to this problem, please?

wisskid commented 1 month ago

This could be a problem. I opened #988 because I suspected that there might be a problem there. Will have to take a look at it.

infira commented 1 month ago

There is a problem within Smarty compiler {if isset($foo) } ..... {/if} will be compiled (v5.4.1) into <?php if ((null !== ($_smarty_tpl->getValue('foo') ?? null))) {?> ..... <?php }?> but it should be <?php if ((null !== ($_smarty_tpl->hasVariable('foo') ?? null))) {?> ..... <?php }?>