Hi,
I'm currently developing my own php template system (yeah, i know there are very good template engines out there (Smarty)) and i came across a small problem with globalization of variables within the Hi,
I'm currently developing my own php template system (yeah, i know there are very good template engines out there (Smarty)) and i came across a small problem with globalization of variables within the template class.
A clanwar script i wrote (for people who don't know what a clanwar is: two clans are battling each other and results are stored (to show others how good you performed sic)) uses this system. A single war entry is fetched through quite complicated mysql-queries (i won't talk about them here :p) and to display a detailed of view of one cw, i use my template engine to make the final html output as changeable as possible (so other clans can adapt my template engine g).
A last function in the clanwar script look like the following:
<code>
// CW_outsng generates a single clanwar page
function CW_outsng ($warid)
{
$war = new CLANWAR ($warid);
$output = new PHPtemplate ("html/cw_html_single.tmpl");
}
</code>
class CLANWAR is an OBJECT with functions and variables. These functions return strings, which the template should (g) output.
The problem here is, that i'm not able to globalize the $war variable within the class, but i explicitly said, that the $war variable should be globalized (through my template file).
<code>
Inside the class:
eval ("global ${variablename};");
</code>
where $variablename carries the string "$war" and though becomes "$war" in the parsed string won't work 🙁
So, instead of being able to make $war global, i had to pass it through an array to access the variable in the class:
<code>
function CW_outsng ($warid)
{
$arrayGlobals['$war'] = new CLANWAR ($warid);
$output = new PHPtemplate ("html/cw_html_single.tmpl", $arrayGlobals);
}
</code>
What am i doing wrong here ?
I think it has something to do with variable scope, because the $war - variable is empty inside the class :/