概念:
$this:可以读取到类里面的属性,还可以读取到方法;
不管生成的对象名称是什么,$this只指向当前对象。
<?php Class User{ protected $name; public function getName($name){ return $this-> name = $name; //$this获取类的属性 } public function sayName(){ return $this->name; } public function funName(){ return $this -> sayName(); //$this获取类的方法 } } $Obj = new User; //生成对象
$Obj->getName("lilei");
echo $Obj -> funName();
?>