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

luk*_*emh 0 php class

我为什么要这样做

Undefined variable: req
Run Code Online (Sandbox Code Playgroud)

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

<?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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ana 7

使用

$this->req
Run Code Online (Sandbox Code Playgroud)

代替

$this->$req
Run Code Online (Sandbox Code Playgroud)

$this->$req = new \DisqusAPI($settings['DISQUS_SECRET_KEY']);
Run Code Online (Sandbox Code Playgroud)