The meaning of $this is to express
The concrete object after instantiation!
We usually declare a class first, then use this class to instantiate an Object!
However, when we declare this class, we want to use the properties or methods of this class within the class itself. What should be said?
For example:
I declare a user class! It contains only one attribute $name;
Class User
{
Public $_name;
}
Now, I'll add a method to the user class. Just use the GetName () method to output the value of the $name property! Copy PHP content to clipboard
Class user{public $name; function GetName () { echo $this->name; }} How to use it? $user 1 = new User (), $user 1->name = ' Zhang San '; $user 1->getname (); This will output Zhang San! $user 2 = new User (); $user 2->name = ' John Doe ';
How do you understand it?
I created two user objects above. $user 1 and $user 2, respectively.
When I call $user 1->getname (). The code in the user class above Echo $this->name; It's the echo $user 1->name;.
That's probably what it means!
In fact, you also do not go to the dead. All you need to know is that it's a code to represent the properties and methods inside the class! The more you think, the more confused!
Found in other places!! Leave it!!
The use of $this