【发布时间】:2013-11-20 17:58:46
【问题描述】:
我正在使用这个库:http://stefangabos.ro/php-libraries/zebra-curl/
在我自己的类结构中检索令牌。
<?php
class getToken
{
private $url = "";
private $customHeaders = array('Content-Type: application/x-www-form-urlencoded',);
private $parameters = array();
private $cacheTime = 600;
private $curl;
public $token = false;
public function __construct(){
require_once('lib/Zebra_cURL.php');
$this->curl = new Zebra_cURL();
$this->curl->cache('cache', $this->cacheTime);
$this->curl->option(CURLOPT_HTTPHEADER, $this->customHeaders);
$this->curl->post($this->url, $this->parameters, __CLASS__.'::tokenCallback');
}
public function returnToken(){
return $this->token;
}
public function tokenCallback($result){
if ($result->response[1] == CURLE_OK) {
$body = str_replace(array('\\/','\"'),array('/','"'), html_entity_decode($result->body));
$tokenStart = stripos($body,"<EncryptedAssertion");
$tokenEnd= stripos($body,"EncryptedAssertion>");
$token = substr($body, $tokenStart, $tokenEnd-$tokenStart);
$this->$token = $token;
}else{
$this->token = false;
}
}
}
在tokenCallback 方法中,我试图设置类$token 参数的值,但是得到以下错误:致命错误:使用$this when not in object context in ....
我尝试使用 self 进行设置,但出现此错误:致命错误:访问未声明的静态属性:getToken::$token
我猜想来自 Zebra_Curl 的回调被实例化的方式是问题所在 - 有人知道如何让它工作吗?
【问题讨论】: