Skip to content
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

isset on array #498

Closed
beaceberq opened this issue Oct 9, 2018 · 5 comments
Closed

isset on array #498

beaceberq opened this issue Oct 9, 2018 · 5 comments

Comments

@beaceberq
Copy link

isset is not generated when we specify the object's property / method as an index

Example:
Code on .tpl:
{if isset($specialOffers[$category->getId()])}gray{/if}
Generated code:
<?php if ((($_smarty_tpl->tpl_vars['specialOffers']->value[$_smarty_tpl->tpl_vars['category']->value->getId()] !== null ))) {?>gray<?php }?>

@JuMiLo
Copy link

JuMiLo commented Oct 12, 2018

Hi,

the same happens when using "variable variables" within isset.

Template code:

{foreach $array AS $key => $val}
	{if !isset(${$key})}
	
	{assign var=$key value=$val}
	
	{/if}
{/foreach}

Generated code:
<?php if (!(($_smarty_tpl->tpl_vars[''.($_smarty_tpl->tpl_vars['key']->value)]->value !== null ))) {?>

The output is generated in the file "smarty_internal_templatecompilerbase.php" (function "compilePHPFunctionCall") on line 633.

Is it safe to replace the responsible line of code
$pa[] = (strpos($p, '(') === false) ? ('isset(' . $p . ')') : ('(' . $p . ' !== null )');
with
$pa[] = 'isset(' . $p . ')';
?

@pszalko
Copy link

pszalko commented Nov 23, 2018

Any update on this issue?

@nenetchi
Copy link

+1 for backticks substitution in array index

  • PHP 7.0.33/7.3.1
  • Smarty 3.1.33

Template

{if isset($foo["prefix_`$bar`"])}
1
{/if}

will generate

if ((($_smarty_tpl->tpl_vars['foo']->value["prefix_".((string)$_smarty_tpl->tpl_vars['bar']->value)] !== null ))) {?>
1
<?php }

with isset missing

@pszalko
Copy link

pszalko commented Mar 12, 2019

I believe this is similar issue to #499
and I hope the workaround from #499 (comment) will help.

Anyway, I hope to see it resolved soon.

wisskid added a commit that referenced this issue Jan 27, 2020
…eed further testing and unit tests.
@wisskid
Copy link
Contributor

wisskid commented Jan 28, 2020

Duplicate of #453

@wisskid wisskid marked this as a duplicate of #453 Jan 28, 2020
@wisskid wisskid closed this as completed Jan 28, 2020
wisskid added a commit that referenced this issue Apr 13, 2020
…ble (#567)

* This appears to fix #453, #498, #499 and possibly more issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants