TL;DR
I think a hasVariable call just before a getValue call is redundant and can be removed from here
|
res = array('$_smarty_tpl->hasVariable(\''.substr(i,1).'\')','$_smarty_tpl->getValue(\''.substr(i,1).'\')'); |
Context
I noticed a strange thing in mt compiled templates: {$foo|isset} and {isset($foo)} do not result in the same compiled code. And interestingly, {isset($bar.a)} does not call hasVaraible and is almost identical to the result of {$bar.a|isset} except for two additional true &&
// {$foo|isset}
((null !== ($_smarty_tpl->getValue('foo') ?? null)))
// {isset($foo)}
((true && ($_smarty_tpl->hasVariable('foo') && null !== ($_smarty_tpl->getValue('foo') ?? null))))
// {$bar.a|isset}
((null !== ($_smarty_tpl->getValue('bar')['a'] ?? null)))
// {isset($bar.a)}
((true && (true && null !== ($_smarty_tpl->getValue('bar')['a'] ?? null))))
Ideally, both functions result in the same compiled code. Historically, I used {isset($bar.a)} because the other syntax was throwing warnings in some circumstances. This seems to be no longer the case.
I also found at least one instance in my code where an {empty($var)} resulted in a hasVariable call. Not sure if this can happen for other functions.
As a side note. The unnecessary true && seems to be only there to avoid handling the first iteration in a loop in the parser.
Also the ?? null part is unnecessary as long as there is no subarray. However, this behavior seems to be more complex to change since the part that adds ?? null does not see what the part in front looks like.
TL;DR
I think a
hasVariablecall just before agetValuecall is redundant and can be removed from heresmarty/src/Parser/TemplateParser.y
Line 885 in aa6edc3
Context
I noticed a strange thing in mt compiled templates:
{$foo|isset}and{isset($foo)}do not result in the same compiled code. And interestingly,{isset($bar.a)}does not callhasVaraibleand is almost identical to the result of{$bar.a|isset}except for two additionaltrue &&Ideally, both functions result in the same compiled code. Historically, I used
{isset($bar.a)}because the other syntax was throwing warnings in some circumstances. This seems to be no longer the case.I also found at least one instance in my code where an
{empty($var)}resulted in ahasVariablecall. Not sure if this can happen for other functions.As a side note. The unnecessary
true &&seems to be only there to avoid handling the first iteration in a loop in the parser.smarty/src/Parser/TemplateParser.y
Line 1117 in aa6edc3
Also the
?? nullpart is unnecessary as long as there is no subarray. However, this behavior seems to be more complex to change since the part that adds?? nulldoes not see what the part in front looks like.