Atitit. Similarities and differences between the design and implementation of global variables in java php, atitit global variables
Atitit. Similarities and differences between the design and implementation of global variables in java php
1. Superglobals variable 1
2. global variables and "global" keyword 1
3. A better way to replace global 1 with $ GLOBALS
4. Differences between global variables of php and java 2
5. Refer to 2
1. Superglobals variable
PHP defines some "Superglobals" variables by default. These variables are automatically merged and can be
Programs are called anywhere, such as $ _ GET and $ _ REQUEST. They generally come from data or other external numbers.
Normally, using these variables will not cause problems, because they are basically not writable.
However, you can use your own global variables.
Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax
2. global variables and "global" keywords
You can import global data to
Within the local range of the function.
. Note that the Global keyword can be defined in the function ).
3. A better way to replace global with $ GLOBALS
This is a "superglobal", or it can be described as an automatic global variable.
The second way to access variables globally is to use a special PHP custom $ GLOBALS array. Previous example
Can be written:
Replace global with $ GLOBALS.
<? PHP
$ W3sky = 1;
$ W3sky2 = 2; function Sum ()
{
$ GLOBALS ['w3sky'] = $ GLOBALS ['w3sky'] + $ GLOBALS ['w3sky2 '];
} Sum ();
Echo $ w3sky2;
?>
In the $ GLOBALS array, each variable is an element. The key name corresponds to the variable name, and the value corresponds to the variable
. $ GLOBALS exists globally because $ GLOBALS is a super global variable. The following example shows
Demonstrate the usage of super global variables:
4. Differences between global variables in php and java
Global is used to define Global variables. However, this Global variable is not applied to the entire website, but to the current page, including all files including include or require.
5. Reference
The use of php volume change global-php application-php tutorial-1.
One of the analysis skills of globals‑learning in PHP.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.