This is a pointer to the current object
<?phpclass human{public $name = "John Doe";p ublic function Eat () { echo $this->name, ' eating ';} Public Function test () { echo $name, ' at Dinner ';}} $li =new Human (); Echo $li->name;//John Doe $li->eat ();//John Doe at dinner. /* Compared to java,c++ the method body wants to access the caller's properties, it must be used $this if not added, then understood as a local variable inside the method. */$li->test ();//notice:undefined Variable:name in C: wamp\www\php\this.php on line 14/****** from the perspective of life to understand $this Nu wa created a person, made a "remorse" method { catch [their] hair [ their] face} The world so many people, regret, Who's got the hair? Who's the face? Zhang San, John Doe? Harry? Can not explain that a reasonable situation can only be understood as "self" ******/?>
This article details PHP $this usage, more relevant content please focus on the PHP Chinese web.