为什么这个类没有找到返回变量?

时间:2014-02-21 13:29:17

标签: php class

为什么我会

Undefined variable: req

当我在我班级的顶层宣布该物业时:

<?php
namespace Craft;

class Disqus_ApiService extends BaseApplicationComponent
{
    private $req = false;

    public function init()
    {
        $d = craft()->plugins->getPlugin('disqus');
        $settings = $d->getSettings();
        $this->$req = new \DisqusAPI($settings['DISQUS_SECRET_KEY']);
    }

    public function trends()
    {
      return $this->req->trends;
    }
}

1 个答案:

答案 0 :(得分:7)

使用

$this->req

而不是

$this->$req

$this->$req = new \DisqusAPI($settings['DISQUS_SECRET_KEY']);