class cls_CoreFunc
{
    public static function func_CheckRobot($str_useragent = '')
    {
private static $str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
private static $str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla'; $str_useragent = empty($str_useragent) ? $_SERVER['HTTP_USER_AGENT'] : $str_useragent; if(!self::func_strexists($str_useragent, 'http://') && preg_match("/($str_browsers)/i", $str_useragent)) {
return false;
} elseif(preg_match("/($str_spiders)/i", $str_useragent)) {
return true;
} else {
return false;
}
    }    public static function func_strexists($str_string, $str_find)
    {
return !(strpos($str_string, $str_find) === FALSE);
    }
}
这段代码有错误,问题就出在将$str_spiders 和 $str_browsers设为私有静态变量
如果我想将$str_spiders 和 $str_browsers设为私有静态变量,该怎么做呢

解决方案 »

  1.   

    class cls_CoreFunc
    {
        private static $str_spiders;
        private static $str_browsers;
        public static function func_CheckRobot($str_useragent = '')
        {
            $this->$str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
            $this->$str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';    $str_useragent = empty($str_useragent) ? $_SERVER['HTTP_USER_AGENT'] : $str_useragent;    if(!self::func_strexists($str_useragent, 'http://') && preg_match("/($str_browsers)/i", $str_useragent)) {
            return false;
        } elseif(preg_match("/($str_spiders)/i", $str_useragent)) {
            return true;
        } else {
            return false;
        }
        }    public static function func_strexists($str_string, $str_find)
        {
        return !(strpos($str_string, $str_find) === FALSE);
        }
    }
      

  2.   


    class cls_CoreFunc
    {
        private static $str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
        private static $str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';//成员变量
        
        public static function func_CheckRobot($str_useragent = '')
        {
    ……
    ……
    ……
      

  3.   

    你要分清楚类的成员变量和函数的里的区域变量的区别。如果这两个变量放在函数内部,他就是一个区域变量,外部是不可见,包括类或者类的外部。
    去掉private static就可以了。
      

  4.   

    谢谢CunningBoy
    一针见血!!