The meaning of the $this represents what is instantiated after the specific object!
We usually declare a class first, then use this class to instantiate the Object!
However, when we declare this class, we want to use the properties or methods of this class within the class itself. How should I say it?
For example:
We declare a user class! It contains only one attribute $name;
ClassName
{
Public $_name;
}
Now let's add a method to the user class. Using the GetName () method, output the value of the $name Property! Copy PHP content to clipboard
PHP Code:
Class User
{
Public $name;
function GetName ()
{
Echo $this->name;
}
}
How to use it?
$user 1=new User ();
$user 1->name= ' John ';
$user 1->getname ();
$user 2=new User ();
$user 2->name= ' Dick ';
$user 2-getname ();
How do you understand it?
I created two user objects above. respectively, $user1 and $user2.
When I call $user1->getname (). The code in the user class above is echo $this->name; it's equivalent to echo $user 1->name;.
That's probably what it means!
In fact, you also do not go into a dead alley. All you need to know is that it's a code name to represent the properties and methods inside the class. Think more and more confused!