Scope and global variables of variables in PHP Basics

Source: Internet
Author: User
Tags php basics
A scope is a range that can be used or visible to a variable in a script. PHP has six basic scope rules.

A scope is a range that can be used or visible to a variable in a script. PHP has six basic scope rules.
1. the built-in Super global variables can be used and visible anywhere in the script.
2. constants, a volume declared, can be globally visible; that is, they can be used outside the function.
3. The global variables declared in a script are visible throughout the script, but not inside the function.
4. when the variable used in the function is declared as a global variable, its name must be consistent with the global variable name.
5. variables created inside the function and declared as static cannot be visible outside the function, but they can be kept during multiple execution of the function.
6. the variable created in the function is local to the function. when the function is terminated, the variable does not exist.

Variable scope

$ _ GET and $ _ POST arrays and some other special variables have their own scope rules. These are called Super global variables that can be used and visible anywhere, including internal and external functions.
The complete list of Super global variables is as follows:
1. $ _ GLOBALS, an array of all global variables.
2. $ _ SERVER: an array of SERVER environment variables.
3. $ _ GET: the variable array passed to the script through the GET method.
4. $ _ POST: the variable array passed to the script through the POST method.
5. $ _ COOKIE, cookie variable array.
6. $ _ REQUEST, an array of all user input variables, including the input content contained in $ _ GET, $ _ POST, and $ _ COOKIE.
7. $ _ FILES, an array of variables related to file upload.
8. $ _ ENV, environment variable array
9. $ _ SESSION, an array of SESSION variables.

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.