View previous topic :: View next topic |
Author |
Message |
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Wed Jun 24, 2015 4:47 am Post subject: Legal Variable in Compiled File? |
|
|
Using Smarty 3.1.25, this is the line of Smarty code:
Code: | {foreach from=$CUSTOM_QUICK_TASKS key=k item=task} | Yes, it's the Smarty 2 syntax.
This is throwing a PHP error:
PHP Parse error: syntax error, unexpected '$_smarty_tpl' (T_VARIABLE)
The line in the cached/compiled template file: Code: |
$foreach_$_smarty_tpl->tpl_vars['task']->value_Sav = $_smarty_tpl->tpl_vars[$_smarty_tpl->tpl_vars['task']->value]; |
The above is not what I see in Smarty 3.1.15.
Is this a legal variable in the compiled file?
(An experiment is underway to use Smarty 3 syntax to determine if PHP still throws an error.)
Could the parse error be attributed to a specific version of PHP? |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Wed Jun 24, 2015 5:03 am Post subject: |
|
|
Rewriting the template code to:
Code: | {foreach $CUSTOM_QUICK_TASKS as $k => $task} |
no longer has PHP throwing an error. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jun 27, 2015 2:47 pm Post subject: |
|
|
You must have used item=$task which is invalid and not the correct item=task as you have written. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jun 27, 2015 2:50 pm Post subject: |
|
|
bsmither wrote: | Rewriting the template code to:
Code: | {foreach $CUSTOM_QUICK_TASKS as $k => $task} |
no longer has PHP throwing an error. |
Little hint: You don't need to use "$k =>". Even if you DO need to acces array key, you can do so with {$item@key}. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Jun 28, 2015 12:49 am Post subject: |
|
|
Quote: | You must have used item=$task |
The code used was exactly as I entered it. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Jun 28, 2015 7:14 am Post subject: |
|
|
Smarty 3.1.25 and other versions do not show this error on
Code: | {foreach from=$CUSTOM_QUICK_TASKS key=k item=task} |
but it would on
Code: | {foreach from=$CUSTOM_QUICK_TASKS key=k item=$task} |
Same thing was reported already here https://github.com/smarty-php/smarty/issues/60 |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Jun 28, 2015 5:08 pm Post subject: |
|
|
Here is my best guess as to what happened:
Version 605 of the application uses Smarty 3.1.15 and has this code:
Code: | {foreach from=$CUSTOM_QUICK_TASKS item=$task} |
Version 606 of the application uses Smarty 3.1.25 and uses this code:
Code: | {foreach from=$CUSTOM_QUICK_TASKS key=k item=task} |
The upgrade process is supposed to delete all compiled templates from the Smarty cache.
My best guess is that this did not happen. Smarty 3.1.25 used a Smarty 3.1.15 cached compiled template.
The application does not collect debug data about whether Smarty recompiled a template or used a cached template, so this is the basis for my guess.
I will also have to assume that Smarty does not check for Smarty version mismatches between itself and compiled templates -- then recompiling on a detected mismatch.
Thank you for your assistance. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Jun 28, 2015 7:19 pm Post subject: |
|
|
Okay I made some additional tests.
Under 3.1.15
Code: | {foreach from=$CUSTOM_QUICK_TASKS item=$task} |
Does compile but it creates invalid code resulting in a lot of E_NOTICE errors.
You must have suppressed E_NOTICE.
Also you must never seen values in the $task variable like in
Code: | {foreach from=$CUSTOM_QUICK_TASKS item=$task}
{$task}
{/foreach} |
This template source is invalid
After the 3.1.25 upgrade Smarty detected the version change and tried to rebuild the compiled and cached files.
Due to some internal changes this time problem was fatal and a compiled file was created with an unrecoverable PHP parsing error.
Also correcting the template source did not help because Smarty tried to include the damaged old compiled file to get some information.
The only solution to get out of this dead lock is to delete all compiled templates manually.
The cache file got never touched because of the compilation fatal error.
For that reason you saw still the 3.1.15 version.
I will try to improve the error handling in the next release. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
|