hi there
in my template engine i init every var being used with NULL to avoid those E_NOTICE messages if they were not provided by the script
example:
template:
{var_1}
{var_2}
{var_3}
compiled template:
echo $data['var_1'];
echo $data['var_2'];
echo $data['var_3'];
script:
$tpl->assign('var_1', 1);
$tpl->assign('var_3', 3);
would produce
1
E_NOTICE
3
setting error_reporting to not display E_NOTICE erros is slower than doing sth. like that:
compiled template:
if (!isset($data['var_1'])) $data['var_1'] = NULL;
if (!isset($data['var_2'])) $data['var_2'] = NULL;
if (!isset($data['var_3'])) $data['var_3'] = NULL;
echo $data['var_1'];
echo $data['var_2'];
echo $data['var_3'];
but this way i have to check every single template var (and normally most of them exist)
so i'm looking for a way to only add missing keys
echo $data['var_1'];
echo $data['var_2'];
echo $data['var_3'];
$data = init_array($data, array('var_1', 'var_2', 'var_3'), NULL);
echo $data['var_1'];
echo $data['var_2'];
echo $data['var_3'];
should output
1
E_NOTICE
3
1
2
3
and of course init_array() should be faster than my current way mentioned above and therefore should not use a loop to check every single entry whether it exists or not
my questions (yeah, this posting is coming to an end 😉)
do you understand what i want?
do you know how to do it?
tia