Atitit. Design and implementation of global variables the similarities and differences of java PHP
1. Super Global (superglobals) "Variable 1
2. Global variables and "global" keyword 1
3. Better way to use $GLOBALS instead of global 1
4. differences in global variables between php and Java 2
5. References 2
1. Super Global (superglobals) "Variable
PHP defines some "super Global (Superglobals)" variables by default, and these variables are actively global. and can be in
Called in any place in the program. For example, $_get and $ _request and so on.
They usually come from data or other external numbers
According to The use of these variables is generally not problematic, as they are essentially non-writable.
But you can use your own global variables.
Author:: Old Wow's paw Attilax Ayron. Email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
2. Global variables and "Global"Keyword
with keyword "global" You can import global data into a
Within the local scope of the function.
. Note that the Global keyword is defined in the function as practical).
3. Better ways to use$GLOBALSAlternativeGlobal
This is a "superglobal", or can describe the narrative as the active global variable.
The second way to access variables at the global scope is to define $GLOBALS arrays by using special PHP itself. The previous sample
Can be written as:
Example using $GLOBALS instead of global
<? PHP
$w 3sky = 1;
$w 3sky2 = 2;function Sum ()
{
$GLOBALS [' W3sky '] = $GLOBALS [' W3sky '] + $GLOBALS [' w3sky2 '];
}sum ();
echo $w 3sky2;
?>
In the $GLOBALS array, each variable is an element, and the key name corresponds to the variable name. value in the corresponding variable
Capacity. $GLOBALS exists globally because $GLOBALS is a hyper-global variable. The following example shows
Shows the use of hyper-global variables:
4. phpand theJavathe difference of global variables
The role of global is to define globals, but this global variable is not applied to the entire site, but to the current page, which contains all the files of the include or require.
5. References
PHP global variable usage -php application -php tutorial - One tutorial net . htm
A _php technique in the analysis of global and $GLOBALS [] in PHP _ script Home . htm
Atitit. The design of global variables and the implementation of Java PHP similarities and differences