Jeff-Lewis / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

Undefined index #225

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. {$allsets[1].sid} in template 3.1.24, where $allsets is an array containing 
arrays; 1 resp. sid are valid indexes
$allsets[1]['sid']= 'foo';
$smarty-assign(array('allsets'=> $allsets));

What is the expected output? What do you see instead?
Expected, showing foo
But getting 
Notice: Undefined index

The particular generated line of code looks like:
<?php echo $_smarty_tpl->tpl_vars['allsets']->value[1][sid];?>
But should look like 
<?php echo $_smarty_tpl->tpl_vars['allsets']->value[1]['sid'];?>

What version of the product are you using? On what operating system?
3.1.24

Please provide any additional information below.

Code was not changed from previous smarty version and worked fine on 3.1.21

if i change the variable name it works as expected tho.
E.g. {$allsets[1].spotid} becomes
<?php echo $_smarty_tpl->tpl_vars['allsets']->value[1]['spotid'];?>

Original issue reported on code.google.com by gavinspe...@gmail.com on 30 May 2015 at 9:33

GoogleCodeExporter commented 9 years ago
The problem is cause by the additional support of constants in Smarty 
´templates.

sid must be defined in your application as constant. 

There is now a naming ambiguity if you write your array access  like $foo.sid

Smarty does now take the value of the constant sid. Either rename the constant 
or the array index.  or use $foo['sid']   

It's not really a bug .

Original comment by Uwe.Tews@googlemail.com on 31 May 2015 at 8:39

GoogleCodeExporter commented 9 years ago
I never defined a "sid" constant. So I was a little confused. However it seems 
that session_start() creates a constant named SID which seems to be a sort of 
semi-documented feature of PHP. Great :(

Original comment by gavinspe...@gmail.com on 31 May 2015 at 9:37