我发现了一些我在PHP中从未见过的东西。int的var_dump显示UNKNOWN:0
Fatal error: Unsupported operand types in ... on line 41
错误消息指下面的语句:
if($this->lastAction + 7200 <= time()) {
}
当我在我的脚本运行前的var_dump的$this->lastAction
我得到的输出:
UNKNOWN:0
我的脚本错误中止
我以前从来没有见过。而且我无法想象将这个值分配给我的变量或在什么情况下会发生这种情况。
有没有人提示或解释这个“价值”来自哪里?
更新1
我发现,如果我在使用PHP 5.3 ENV运行相同的设置,我得到,而不是错误:
Object of class stdClass could not be converted to int ... on line 41
但我从来没有分配stdClass
实例这个变量。
UPDATE 2
问题在PHP 5.5.19
具有相同的误差也存在如在5.4.28
版本。
AuthHandler.php
abstract class AuthHandler
{
protected $lastAction;
public function __construct()
{
$this->lastAction = isset($_SESSION['last_action']) ? $_SESSION['last_action'] : time();
if($this->lastAction + 7200 <= time()) {
$this->logout();
}
$this->lastAction = time();
}
public function logout()
{
session_destroy();
session_regenerate_id();
$this->lastAction = null;
}
public function __destruct()
{
$_SESSION['last_action'] = $this->lastAction;
}
}
DBAuthHandler.php
class DBAuthHandler extends AuthHandler
{
// other stuff here
}
'$ this'是什么类型? – 2014-11-24 07:36:32
您可以使用[gettype()](http://php.net/manual/en/function.gettype.php)输出'$ this-> lastAction'的类型。 – Jerodev 2014-11-24 07:37:37
什么是您的PHP版本? – sectus 2014-11-24 07:38:38