2017-10-20 139 views
1

我只是想不通,为什么这个错误甚至显示出来:PHP类未定义的变量(但是它被定义)

注意:未定义的变量:authTime在/.../classname.class。上的PHP线33

class ClassName { 

private $authTime = null; 


const API_URL  = '...'; 
const CLIENT_ID  = '...'; 
const CLIENT_SECRET = '...'; 

private static $TOKEN  = NULL; 


public function __construct() { 
$this->_authTime = $authTime; // <----- Line 33 
if(!self::$TOKEN OR $this->AuthTime('GET') > 3600 OR !$this->_authTime) { 
    self::authorise(); 
} 
} 

public function getAuthTime() { 
    return $this->_authTime; // Returns NULL 
} 
+0

它在哪里定义?它是在构造函数声明之后使用的吗?但从未宣布。为什么在房产前强调? '_authTime' – mega6382

+0

https://stackoverflow.com/review/suggested-edits/17688430为什么编辑加入咆哮BACK在? –

回答

3

我看到$authTime未在构造函数中所定义。我想你想这样做:

$this->_authTime = $this->authTime; 
+0

好的...:o摆脱了错误,但是当我尝试指定该变量的值$ this-> authTime = time();'我得到了同样的错误。 **编辑:**我的不好,我在一个静态函数中调用'$ this->'。谢谢您的帮助。我的英雄! :D –

+0

不客气。我很高兴我可以帮助:) –