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