2017-10-20 141 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

不客氣。我很高興我可以幫助:) –