Strange, static variables cannot be assigned values! Solution

Source: Internet
Author: User
Strange, static variables cannot be assigned values! The program is as follows: classdbManage {& nbsp; publicstatic $ siteInfo; Site Information & nbsp; ** & nbsp; * default execution & nbsp; * & nbsp; function _ construct () {& nbsp; $ do Strange, static variables cannot be assigned a value!
The procedure is as follows:
Class dbManage {
Public static $ siteInfo; // site information

/**
* Default execution
*/

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;
}
}

The problem lies in the red line. Explicit $ _ COOKIE ["site"] contains data, but self: $ siteInfo is always empty. Which of the following experts can help me see why?

------ Solution --------------------
How do you know that self: $ siteInfo is always empty ???


------ Solution --------------------
Self: $ siteInfo = $ _ COOKIE ["site"]; if (empty (self: $ siteInfo) | self: $ siteInfo ["domain"]! = $ Domain ){


You will assign values using $ _ COOKIE ["site"] later, and use $ siteInfo ["domain"] later

Question: $ _ COOKIE ["site"] or $ siteInfo is an array? Where does domain come from?
------ Solution --------------------
Self: $ siteInfo = $ _ COOKIE ["site"]; // is this value an array?
If (empty (self: $ siteInfo) | self: $ siteInfo ["domain"]! = $ Domain) // You can output a value in the condition to see if there is any execution?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.