: This article mainly introduces "php and MySQLWeb development"-Reading Notes 2. if you are interested in the PHP Tutorial, refer to it. 15 understand the scope
The scope of a variable can control where the variable is visible and available. Different programming languages have different variable scope rules. PHP has simple rules:
1. the variable scope declared in the function starts from the statement that declared them to the end of the function. This is called the function scope. These variables are called local variables.
GetMessage () ;}$ ob-> g (); // Note: $ ob variable does not have function scope}
2. the variable scope declared outside the function starts from the statement that declared them to the end of the file, rather than inside the function. This is called global scope. These variables are called global variables.
3. Special Super global variables are visible inside and outside the function. For example, _ GET, _ POST, _ FILE.
4 Using require () and include () does not affect the scope. If these two statements are used inside the function, the function scope applies. If it is not within the function, the global scope applies.
5. the keyword global can be used to manually specify that the variables defined or used in a word function have a global scope.
6. you can manually delete a variable by calling unset ($ variable_name. If the variable is deleted, it is not in the scope specified by the parameter.