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:
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. Use the GetName () method to output the value of the $name property! Copy PHP content to clipboard
PHP Code:
Copy Code code as follows:
Class User
{
Public $name;
function GetName ()
{
Echo $this->name;
}
}
How to use it?
$user 1 = new User ();
$user 1->name = ' John ';
$user 1->getname (); This will output John!
$user 2 = new User ();
$user 2->name = ' dick ';
$user 2->getname (); This will output dick!
How do you understand it?
I created two user objects above. are $user 1 and $user 2 respectively.
When I call $user 1->getname (). Code echo $this->name in the user class above; is the equivalent of Echo $user 1->name;.
That's probably what it means!