概念:
$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();
?>