Home >Backend Development >PHP Tutorial >Detailed explanation of PHP object-oriented this binding
This article mainly shares with you the detailed explanation of PHP object-oriented this binding. It mainly explains it to you in the form of code. I hope it can help you.
About this binding
class Human { public $name = 'lisi'; public function who() { echo $this->name; } /* public function test() { echo $name; } *//* 和java、c++相比 方法体内想访问调用者的属性,必须用$this 如果不加,则理解为方法内部的一个局部变量. */}$a = new Human();echo $a->name,'<br >'; //lisi$a->who(); //lisi//$a->test();
About this binding
class Human { public $name = 'lisi'; public function who() { echo $this->name; } /* public function test() { echo $name; } *//* 和java、c++相比 方法体内想访问调用者的属性,必须用$this 如果不加,则理解为方法内部的一个局部变量. */}$a = new Human();echo $a->name,'<br >'; //lisi$a->who(); //lisi//$a->test();
Related recommendations:
Detailed explanation of this binding in JavaScript
The above is the detailed content of Detailed explanation of PHP object-oriented this binding. For more information, please follow other related articles on the PHP Chinese website!