Php understands the scope of variables

Source: Internet
Author: User
Php understands that the scope of a variable refers to the scope that a variable can be used or visible 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 can be globally visible once declared; that is, they can be used both inside and outside the function. 3. declare in a script that php understands the scope of variables

Scope refers to the range in which a variable in a script can be used or visible. php has six basic scope rules.

1. the built-in Super global variables can be used and visible anywhere in the script.

2. constants can be globally visible once declared; that is, they can be used both inside and outside the function.

3. The global variables declared in a script are visible throughout the script, but not within 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 this value can be kept during multiple function executions.

6. the variable created in the function is local to the function. when the function is terminated, the variable does not exist.

$ _ 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.

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.