Questions about global! Solution

Source: Internet
Author: User
Questions about global! I found that many programs, such as dede, all like to declare a global variable in a function, but I have searched the whole site and have not seen a globally variable with the same name defined by the outside. for example: functionSetVar ($ k, $ v) {global $ _ vars; questions about global!
I found that many programs, including dede, all like to declare a global variable in a function, but I have searched the entire site and have not seen external defined global variables of the same name,

For example:


Function SetVar ($ k, $ v)
{
Global $ _ vars;
If (! Isset ($ _ vars [$ k])
{
$ _ Vars [$ k] = $ v;
}
}

Function GetVar ($ k)
{
Global $ _ vars;
Return isset ($ _ vars [$ k])? $ _ Vars [$ k]: '';
}

Here $ _ vars; is defined for the first time in the SetVar function, whether it means that a global variable has been defined here, and the following GetVar function

Is $ _ var the same global variable as $ _ var in other places?

What does this mean?





------ Solution --------------------
If this variable is not in global, it will be created as a global variable.
------ Solution --------------------
A variable is declared as global. the variable remains unique throughout the project!
------ Solution --------------------
It is usually defined on the portal page or the page where variables are uniformly defined.

This is a declaration, not a definition. All php variables may become global variables.
------ Solution --------------------
Discussion
I found that many programs, including dede, all like to declare a global variable in a function, but I have searched the entire site and have not seen external defined global variables of the same name,

For example:


Function SetVar ($ k, $ v)
{
Global $ _ vars;
If (! Isset ($ _ vars [$ k])
{
$ _ Vars [$ k] = $ v;
}
}

Function GetVar ($ k ......

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.