dqd3690 2010-06-10 10:51
浏览 8
已采纳

从类成员返回引用?

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!

  • 写回答

2条回答 默认 最新

  • doulu5717 2010-06-10 11:07
    关注

    You're using $this->template_compile_path; to initialize Smarty. Have you initialized this? On a different note have you set PHP to display errors? Have you looked in your web server error log?

    If you have a doubt about what a function returns use print_r on the result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度