怪事,静态变量不能赋值!
程序如下:
class dbManage {
public static $siteInfo; //站点信息
/**
* 默认执行
*/
function __construct() {
$domainKey = strtolower($_SERVER['SERVER_NAME']);
$domainKey = str_ireplace("www.", "", $domainKey);
self::$siteInfo = dbManage::getSiteInfo($domainKey);
}
public static function getSiteInfo($domain) {
self::$siteInfo = $_COOKIE["site"]; if (empty(self::$siteInfo) || self::$siteInfo["domain"] != $domain) {
$sql = "select * from site_config where domain='{$domain}'";
self::$siteInfo = self::queryArray($sql);
self::setCookie(self::$siteInfo, "site");
}
return self::$siteInfo;
}
}
问题出在红字那一行。明明$_COOKIE["site"]中有数据,可是self::$siteInfo中始终为空。请哪位高手帮我看看是什么原因?
------解决方案--------------------你如何知道 self::$siteInfo中始终为空 ???
------解决方案--------------------self::$siteInfo = $_COOKIE["site"]; if (empty(self::$siteInfo) || self::$siteInfo["domain"] != $domain) {
你一会儿用$_COOKIE["site"]来赋值,一会儿又要使用$siteInfo["domain"]
试问,$_COOKIE["site"]或$siteInfo是数组么?domain这个哪里来?
------解决方案--------------------
self::$siteInfo = $_COOKIE["site"];//这个值是数组?
if (empty(self::$siteInfo) || self::$siteInfo["domain"] != $domain)//你在条件内输出个值看下有没有执行不就知道了?