$ This usage in PHP

Source: Internet
Author: User
Welcome to the Linux community forum and interact with the 2 million technical staff. this is the pointer to the current object [php] viewplaincopyprint? Classhuman {public $ name Li Si; publicfunctioneat () {echo $ this-name, at dinner;} publicfunctiontest () {echo $ name, at dinner ;}}

Welcome to the Linux community forum and interact with the 2 million technical staff> this is the pointer to the current object [php] view plaincopyprint? Class human {public $ name = ""; public function eat () {echo $ this-name, 'at dinner ';} public function test () {echo $ name, 'At dinner ';}}

Welcome to the Linux community forum and interact with 2 million technicians>

This is the pointer to the current object [php] view plaincopyprint?

Class human {

Public $ name = "Li Si ";

Public function eat (){

Echo $ this-> name, 'at dinner ';

}

Public function test (){

Echo $ name, 'at dinner ';

}

}

$ Li = new human ();

Echo $ li-> name; // li Si

$ Li-> eat (); // li Si is eating.

/*

Compared with java and c ++

You must use $ this

If this parameter is not added, it is considered as a local variable in the method.

*/

$ Li-> test (); // Notice: Undefined variable: name in C: \ wamp \ www \ php \ this. php on line 14

/******

Understanding $ this from the perspective of life

A "remorse" method was created when the nvwa was created.

{

Capture your hair

Smoke your own face

}

There are so many people in the world,

Who's the hair when I regret it?

Who's the face?

Zhang San, Li Si? Wang Wu? Cannot describe reasonable situations

It can only be understood as "yourself"

******/

?>

Class human {

Public $ name = "Li Si ";

Public function eat (){

Echo $ this-> name, 'at dinner ';

}

Public function test (){

Echo $ name, 'at dinner ';

}

}

$ Li = new human ();

Echo $ li-> name; // li Si

$ Li-> eat (); // li Si is eating.

/*

Compared with java and c ++

You must use $ this

If this parameter is not added, it is considered as a local variable in the method.

*/

$ Li-> test (); // Notice: Undefined variable: name in C: \ wamp \ www \ php \ this. php on line 14

/******

Understanding $ this from the perspective of life

A "remorse" method was created when the nvwa was created.

{

Capture your hair

Smoke your own face

}

There are so many people in the world,

Who's the hair when I regret it?

Who's the face?

Zhang San, Li Si? Wang Wu? Cannot describe reasonable situations

It can only be understood as "yourself"

******/

?>

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.