$ This usage in PHP. This is the pointer to the current object [php] viewplaincopyprint ?? Phpclasshuman {public $ name Li Si; publicfunctioneat () {echo $ this-name, at dinner;} publicfunctiontest () {echo 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"
******/
?>
Lateral view plaincopyprint? ? Php class human {public $ name = Li Si; public function eat () {echo $ this-name, at dinner;} public function test () {echo...