"Base" PHP variable and variable scope, PHP variable scope _php Tutorial

Source: Internet
Author: User
Tags variable scope

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

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