PHP类无法正常工作

时间:2011-10-14 16:55:14

标签: php

它出错了,我想要它做的就是返回$ fcEnable作为这个类中数据库的结果.......

  

解析错误:语法错误,意外的T_VARIABLE   /home/site/page.php

$VisitorIP = ip2long($_SERVER['REMOTE_ADDR']);
$IPCheckQ = mysql_query("SELECT * FROM `blah` WHERE `ip` = '" . $VisitorIP . "'");
$IPCheckR = mysql_fetch_array($IPCheckQ);
class GeoIP extends Page {
 public $fcEnable = $IPCheckR['x'];
}

2 个答案:

答案 0 :(得分:1)

您不能将另一个变量分配给类中的var。

class GeoIP extends Page 
{
 public $fcEnable;

 function __construct($fcEnable = null)
 {
        $this->fcEnable = $fcEnable
 }

}

答案 1 :(得分:-1)

$fcEnable属于GeoIP的范围。类的范围之外的代码需要在类中执行,或者像这样:

class GeoIP extends Page
{
    public $fcEnable;

    public function __construct( $ipcheck )
    {
         $this->fcEnable = $ipcheck['x'];
    }
}

$VisitorIP = ip2long($_SERVER['REMOTE_ADDR']);
$IPCheckQ = mysql_query("SELECT * FROM `blah` WHERE `ip` = '" . $VisitorIP . "'");
$IPCheckR = mysql_fetch_array($IPCheckQ);
$gip = new GeoIP( $IPCheckR );