Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Legal Variable in Compiled File?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Wed Jun 24, 2015 4:47 am    Post subject: Legal Variable in Compiled File? Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Wed Jun 24, 2015 5:03 am    Post subject: Reply with quote

Rewriting the template code to:
Code:
{foreach $CUSTOM_QUICK_TASKS as $k => $task}

no longer has PHP throwing an error.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 27, 2015 2:47 pm    Post subject: Reply with quote

You must have used item=$task which is invalid and not the correct item=task as you have written.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Jun 27, 2015 2:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Jun 28, 2015 12:49 am    Post subject: Reply with quote

Quote:
You must have used item=$task


The code used was exactly as I entered it.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jun 28, 2015 7:14 am    Post subject: Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Jun 28, 2015 5:08 pm    Post subject: Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jun 28, 2015 7:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jul 01, 2015 2:08 am    Post subject: Reply with quote

See https://github.com/smarty-php/smarty/issues/60
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP