還是不調(diào)清楚$this的含義和作用
還是不調(diào)清楚$this的含義和作用,誰能為我解答一下
class Car {
? ? private $speed = 0;
? ??
? ? public function getSpeed() {
? ? ? ? return $this->speed;
? ? }
? ??
? ? protected function speedUp() {
? ? ? ? $this->speed += 10;
? ? }
? ??
? ? //增加start方法,使他能夠調(diào)用受保護(hù)的方法speedUp實(shí)現(xiàn)加速10
? ? public function start(){
? ? ? ?return $this->speedup();
? ? }
}
2015-08-20
class Car {//定義一個(gè)類
? ? private $speed = 0;//定義屬性
? ? public function getSpeed() {//定義方法
? ? ? ? return $this->speed;//$this 是php里面的偽變量,表示對(duì)象自身.可以通過$this->的方式訪問對(duì)象的屬性和方法,這里是返回speed屬性的值
? ? }
}
http://idcbgp.cn/learn/184? 這里面有詳細(xì)的介紹面向?qū)ο蟮恼n程