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

smarty isset not working notice Undefined offset 3.1.32v and 3.1.33v #499

Closed
jvalencia74 opened this issue Oct 17, 2018 · 6 comments
Closed

Comments

@jvalencia74
Copy link

when trying to update it happens to me in both versions and it is in a section loop

{section name=field loop=$result}
{if ((isset($result[field].changeState)) and ($role_update == "1"))}
{else}
{/if}
{/section}

template return error

smarty\ce7fa0ecf0a71469a5f7beae553a6f8123a19440_0.file.Maintenance.Dispatchers.input.tpl.php:203] Undefined index: changeState

it only happens when reading an array with section

I have the same error in several templates with different index

works well in 3.1.30v

tks

@mylemans
Copy link

I have the same issue, almost (if not all) my sections broke!

@pszalko
Copy link

pszalko commented Nov 23, 2018

I can confirm this issue for me too. Smarty code inside {section} does not generate isset().

@jeckyl
Copy link

jeckyl commented Jan 10, 2019

Hi,
I also confirm this concern. Quite embarrassing in the development of testing its variables to realize that the test itself does not work.

@tmcreativeltd
Copy link

Come on Smarty... surely this is what isset is for? Any plans on a fix?

@pszalko
Copy link

pszalko commented Mar 12, 2019

I have encountered this issue again...

Here is some follow up if and workaround that I found.

Use case:
The following Smarty code raised PHP Notice:

<li class="{if isset($availabilityDates[$group->getId()][$dateString]) == true} selected{/if}"

After short inspection:

1. Investigation:
I have found out that this issue might be related to implementation in smarty_internal_templatecompilerbase.php:633 (for Smarty v3.1.33):

$pa[] = (strpos($p, '(') === false) ? ('isset(' . $p . ')') : ('(' . $p . ' !== null )');

Variable $p holds the exact line of the template that is being parsed by Smarty.
In that particular line my template code is isset(... [$group->getId()]...).
Do you see already what's going on? Smarty looks for ( char, and if found isset(...) is stripped and replaced by !== null in compiled template.

2. Workaround:
Remove any parenthesis from argument of isset() method.

Here is workaround implementation for my use case:

{assign var="groupId" value=$group->getId()}
<li class="{if isset($availabilityDates[$groupId][$dateString]) == true} selected{/if}"

I hope this knowledge will help someone in Smarty team to resolve this issue.

@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

6 participants