源码如下:
class Safe
{
public function addslashes_deep($value)
{
$value = is_array($value) ? array_map(array(self,'addslashes_deep'),$value) : addslashes($value);
return $value;
}
public function cklogin($ses)
{
if(!isset($_SESSION[$ses]))
{
$this->warning('无效的访问,请先登录本系统!',"top.location.href='index.php';");
}
}
public function warning($msg,$do='')
{
echo " <html>
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<script language='javascript'>";
echo 'alert("'.$msg.'");';
echo $do;
echo '</script>';
echo ' </head>
<body>
</body>
</html>';
}
}
用 Safe::cklogin('user'); 调用之后,显示错误:
Fatal error: Using $this when not in object context in /usr/web/oa/OA/include/lib/inc.class.safe.php on line ...提示错误行代码是:
$this->warning('无效的访问,请先登录本系统!',"top.location.href='index.php';");
同样的问题,在我自己的机器上没有出现,但在公司的一台机子上去出现了,不知为什么,高人请教了!谢谢!
谢谢!
class Safe
{
public function addslashes_deep($value)
{
$value = is_array($value) ? array_map(array(self,'addslashes_deep'),$value) : addslashes($value);
return $value;
}
public function cklogin($ses)
{
if(!isset($_SESSION[$ses]))
{
$this->warning('无效的访问,请先登录本系统!',"top.location.href='index.php';");
}
}
public function warning($msg,$do='')
{
echo " <html>
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<script language='javascript'>";
echo 'alert("'.$msg.'");';
echo $do;
echo '</script>';
echo ' </head>
<body>
</body>
</html>';
}
}
用 Safe::cklogin('user'); 调用之后,显示错误:
Fatal error: Using $this when not in object context in /usr/web/oa/OA/include/lib/inc.class.safe.php on line ...提示错误行代码是:
$this->warning('无效的访问,请先登录本系统!',"top.location.href='index.php';");
同样的问题,在我自己的机器上没有出现,但在公司的一台机子上去出现了,不知为什么,高人请教了!谢谢!
谢谢!
正确的方式应该是
$xxx = new Safe();
$xxx->cklogin($ses);
这样调用是不允许操作成员变量和成员函数的.
你还是没有明白类.类没有实例化,如何能产生$this.
上面说法可能不太准备.正确的说法应该是,类没有被实例化之前,调用的成员函数内是不允许用$this来访问成员函数或者成员变量.
难道是php版本不一样.
我个人是 windows ,郁闷,我也怪。哈哈,总之,还是非常感谢你!