Home  >  Article  >  Backend Development  >  怪事,静态变量不能赋值!解决思路

怪事,静态变量不能赋值!解决思路

WBOY
WBOYOriginal
2016-06-13 10:03:061580browse

怪事,静态变量不能赋值!
程序如下:
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)//你在条件内输出个值看下有没有执行不就知道了?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn