is the scope of PHP local variables scoped to <?php?>?

Source: Internet
Author: User
The scope of PHP local variables is ?

Reply content:

What is the scope range of PHP local variables ?

The scope of variables in PHP can be divided into:
Hyper-Global variables : can be accessed in any scope of a script and can be used directly in a local scope without the need for global declaration.
such as $globals,$_env,$_server,$_get,$_post,$_files,$_session,$_cookie and so on.
Global Variables : Declared variables are not inside language structures such as class,function. If you want to use global variables internally, such as class,function, you need to $globals with the keyword Global or the Hyper global variable.
local variable : A variable declared inside a struct statement such as Class,function.
static variable : A variable declared with the keyword static in function, the value of the static variable is retained until the current requested script finishes running, such as the database connection object that can be used to save.

The scope of a local variable is the function head to the end of the function.

A PHP file, regardless of a few tags, is actually coherent. Statements that are outside the label are considered echo . The label also does not affect the scope.

Local variables are also called internal variables, and the variables declared inside the actual function are also limited to the inside of the function, and it is illegal to use the variable after leaving the function.

The variables defined inside the function are local variables.

Local variables: is a variable defined in the function body, used in the function body, if you want to use him outside the function body, you have to convert him into a global variable use, the same way in the function of the use of global variables, one is passed as a parameter to the inside of the function, and the other is to use the Super Global array $globals[' variable name

  • 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.