In php, what does $ this-) mean ?. What is the meaning of $ this? the specific object after instantiation! We generally declare a class first, and then use this class to instantiate the object! However, when we declare this class, what is the meaning of $ this and the specific object after instantiation!
We generally declare a class first, and then use this class to instantiate the object!
However, when we declare this class, we want to use the attributes or methods of this class in the class itself. What should I do?
For example:
We declare a User class! It only contains one attribute $ name;
Classname
{
Public $ _ name;
}
Now we add a method to the User class. Use the getName () method to output the value of the $ name attribute! Copy the php content to the clipboard.
Php code:
Class User
{
Public $ name;
Function getName ()
{
Echo $ this-> name;
}
}
// How to use it?
$ User1 = new User ();
$ User1-> name = 'zhangsan ';
$ User1-> getName ();
$ User2 = new User ();
$ User2-> name = 'Li si ';
$ User2-getName ();
How can this problem be solved?
I created two User objects above. $ User1 and $ user2.
When I call $ user1-> getName. The above User class code echo $ this-> name; is equivalent to echo $ user1-> name;
This is probably the meaning!
In fact, you do not want to go to the tip. You only need to know that it is a code used to indicate the internal attributes and methods of the class! The more you think about it, the more confused you are!
What is the meaning of the struct? the specific object after instantiation! We generally declare a class first, and then use this class to instantiate the object! However, when we declare this class...