Atitit. Similarities and differences between the design and implementation of global variables in java php, atitit global variables

Source: Internet
Author: User

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.

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.