【发布时间】:2014-11-24 07:32:21
【问题描述】:
我发现了一些我以前在 PHP 中从未见过的东西。我的脚本因错误而中止:
致命错误:第 41 行 ... 中不支持的操作数类型
错误信息是指以下语句:
if($this->lastAction + 7200 <= time()) {
}
当我在脚本中的操作之前 var_dump $this->lastAction 时,我得到了输出:
UNKNOWN:0
我以前从未见过。而且我无法想象这个值是在哪里分配给我的变量的,或者在什么条件下会发生这种情况。
有没有人暗示或解释这个“价值”来自哪里?
更新 1
我发现如果我在使用 PHP 5.3 的环境上运行相同的设置,我会得到错误:
第 41 行 stdClass 类的对象无法转换为 int ...
但我从来没有将stdClass 实例分配给这个变量。
更新 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是什么类型? -
你能用gettype()输出
$this->lastAction的类型吗? -
它看起来像一个错误。你能创建最少的可重现代码吗?
-
好的。我想,那么我们需要更多关于这个类的信息来进一步调查。
-
添加了我的类定义的示例代码
标签: php