"Base" PHP variable and variable scope, PHP variable scope
The newly-learned PHP, more interesting syntax, recorded.
1. Scope of variables
The scope is only two global and local,global relative to the entire. php file, Local is the minimum range, which is the closest range of distance variables, such as: In a function, in a class medium.
2. Declaration of variables
It is possible that the PHP variable is unique to the $ symbol, so declaring the PHP variable does not require a keyword (except in the Class) and is automatically created when the first assignment is made.
Class is unique, because the class has member properties of private, public, protected, the declaration of a variable in a class is required for keyword decoration. Use the previously mentioned keyword or the keyword var, but you cannot share it.
3. Sample Description
1
Php2 3 $VarFile= "Var_file";//Variable Declaration4 5 $nr=Array("\ n", "\ R", "\n\r", "\ r \ n"));6 7 8 classTestClass9 { Ten /* One * declared with VAR declaration and private keyword, respectively A * $var = value; This cannot be - * var private $var; This cannot be - * var private $var = value; the * var $var; this cannot be - */ - - var $VarClass= ' varclass declared by keyword Var '; + Private $VarClass 2= ' VarClass2 declared by keyword private '; - + /* A * Add global keyword, use global scope variables at * The method of declaring variables in a function is the same as global - */ - - functionGetallvar () { - Global $VarFile; - $VarFunction= ' Var_function '; in - $Temp= "$VarFile=".$VarFile." \ r \ n ". to"Varclass=".$this->varclass. " \ r \ n ". +"Varclass2=".$this->varclass2. " \ r \ n ". -"Varfunction=".$VarFunction." \ r \ n "; the * $ return Str_replace($GLOBALS[' Nr '], "
",$Temp);Panax Notoginseng } - the + A } the + $MyClass=NewTestClass ("Zzy"); - Echo $MyClass-Getallvar (); $ $?>
http://www.bkjia.com/PHPjc/1126174.html www.bkjia.com true http://www.bkjia.com/PHPjc/1126174.html techarticle "Basic" PHP variables and variable scope, PHP variable scope of the newly-learned PHP, more interesting syntax, recorded. 1. The scope scope of a variable is only two global and Local,global phases ...