[Basics] PHP variables and variable scopes, and php variable scopes. [Basic] PHP variables and variable scopes. php variable scopes are newly learned. interesting syntax is recorded. 1. the scope and scope of variables are divided into two Global and Local, Global. [basic] PHP variables and variable scopes, and php variable scopes.
New PHP, more interesting syntax, record.
1. Scope of variables
The scope can only be divided into two Global and Local. compared with the entire. php file, Global is the smallest Local range and the closest range to the variable. for example, in a function, the class is medium.
2. variable declaration
It may be because the PHP variable has a unique $ symbol, so it does not need keywords to declare the PHP variable (except in the class). it is automatically created when the first value is assigned.
The class is quite unique. because the class has the member attributes private, public, and protected, you need to modify keywords when declaring variables in the class. The preceding keyword or var is used, but the two cannot be shared.
3. example
1
VarClass. "\ r \ n ". 32 "VarClass2 = ". $ this-> VarClass2. "\ r \ n ". 33 "VarFunction = ". $ VarFunction. "\ r \ n"; 34 35 36 return str_replace ($ GLOBALS ['NR '],"
", $ Temp); 37} 38 39 40 41} 42 43 $ MyClass = new TestClass (" success "); 44 echo $ MyClass-> GetAllVar (); 45 46?>
Let's record some interesting syntaxes that I learned from PHP. 1. the scope of the variable is divided into two Global and Local, Global...