Returning a reference from a Class member?
- by nebukadnezzar
Hi, I've a class that basically looks like this:
class App {
public function newTemplate($filename, $vars=array())
{
$smarty = new Smarty;
$smarty->compile_dir = $this->template_compile_path;
if(count($vars) > 0)
{
foreach($vars as $v_key => $v_name)
{
$smarty->assign($v_key, $v_name);
}
}
return $smarty;
}
}
However, when I create a Instance of 'App', the reference to $smarty seems broken, as every call to the membermethods don't seem to do anything:
$app = new App;
$tpl = $app->newTemplate("index.tmpl");
$tpl->assign("foo", "bar"); // {$foo} does not appear with "bar" in the template
Now I wonder why? Of course I tried to use references:
...
public function &newTemplate()
...
... But that doesn't work. Variable references don't seem to work either:
...
$tpl = &$app->newTemplate("index.tmpl");
...
What is causing PHP here not to return a proper reference? Help is very appreciated!