[Basic] PHP variable and variable scope, php variable scope _ PHP Tutorial

Source: Internet
Author: User
[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...

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.