【问题标题】:PHP CLASS Undefined variable (But it is defined) [duplicate]PHP CLASS未定义变量(但已定义)[重复]
【发布时间】:2017-10-20 20:27:52
【问题描述】:

我就是想不通为什么会出现这个错误:

注意:未定义变量:/.../classname.class.php 第 33 行中的 authTime

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
}

【问题讨论】:

标签: php class variables null undefined


【解决方案1】:

我看到$authTime 没有在构造函数中定义。我想你想做:

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

【讨论】:

  • Ok... :o 这消除了错误,但是当我尝试指定该变量 $this-&gt;authTime = time(); 的值时,我得到了同样的错误。 编辑: 我的错,我在静态函数中调用$this-&gt;。谢谢您的帮助。我的英雄! :D
  • 不客气。我很高兴能帮上忙 :)
猜你喜欢
  • 2014-10-09
  • 2018-08-06
  • 1970-01-01
  • 2022-12-31
  • 1970-01-01
  • 2019-10-01
  • 2020-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多