PHP类不从父级继承构造函数

时间:2016-06-16 18:48:39

标签: php class oop inheritance

我有以下类,它有一个为私有变量设置值的构造函数:

class APISession {

    //Definidas en el constructor
    private $db;
    private $logDB;
    private $logWS;

    //Definidas acorde a la funcion
    private $userID;

    public function __construct($instanceDB, $instanceDBLog, $instanceWSLog) {
        $this->db = $instanceDB;
        $this->logDB = $instanceDBLog;
        $this->logWS = $instanceWSLog;
    }

}

然后我有一个从前一个继承的子类

require_once 'claseAPISession.php';

class FBSession extends APISession {

    private $fbAppId = '99999999999999';
    private $fbAppSecret = 'xxxxxxxxxxxxxxx';
//Instancia de la App
    private $FBApp;

    public function __construct($instanceDB, $instanceDBLog, $instanceWSLog) {
        parent::__construct($instanceDB, $instanceDBLog, $instanceWSLog);
        //Genera la instancia de la APP de Facebook
        $fb = new Facebook\Facebook([
            'app_id' => $this->fbAppId,
            'app_secret' => $this->fbAppSecret,
            'default_graph_version' => 'v2.5',
        ]);
        $this->FBApp = $fb;
    }

    public function verifyRegister($accessToken) {
        //$oAuth2Client = $this->FBApp->getOAuth2Client();
        //$tokenMetadata = $oAuth2Client->debugToken($accessToken);
        //$tokenMetadata->validateAppId($this->fbAppId);
        $params = ["access_token" => $accessToken];
        return $this->makeGETAPIRequest($params);
    }

    private function makeGETAPIRequest($params){
        $request = $this->FBApp->request('GET', '/me', $params);
        try {
            $response = $this->FBApp->getClient()->sendRequest($request);
        } catch (Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            echo "Facebook Graph API retorno error " . $e->getMessage();
            $this->logDB->error('Graph returned an error: ' . $e->getMessage());
            exit();
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo "Facebook SDK retorno error " . $e->getMessage();
            $this->logDB->error('Facebook SDK returned an error: ' . $e->getMessage());
            exit();
        }
        //$graphNode = $response->getGraphNode();
        return $graphNode;
    }

}

我打电话给第二节这样的

$session = new FBSession($this->db, $this->logDB, $this->logWS);
$v = $session->verifyRegister($httpBody['accessTokenFB']);

调用第二个类时我得到的错误是

  

注意:未定义的属性:C:\ wamp \ www \ recomendado \ api \ clases \ claseFBSession.php中的FBSession :: $ logDB

这意味着它不是从构造函数继承变量,我怎么能设法做到这一点?

0 个答案:

没有答案