In php, what does $ this-& amp; gt; mean. $ This indicates 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 think $ this indicates 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:
I declare a User class! It only contains one attribute $ name;
Class User
{
Public $ _ name;
}
Now, I 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 (); // three items are output here!
$ User2 = new User ();
$ User2-> name = 'Li si ';
$ User2-> getName (); // Li Si will be output here!
How can this problem be solved?
I created two User objects above. $ User1 and $ user2 respectively.
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!
Found elsewhere !! Left !!
The definition of objects is 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...