新聞中心
->聯(lián)合使用,專門用來完成對象內(nèi)部成員之間的訪問。如下所示:
站在用戶的角度思考問題,與客戶深入溝通,找到云城網(wǎng)站設(shè)計與云城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋云城地區(qū)。
$this -> 成員屬性;
$this -> 成員方法(參數(shù)列表);
比如在 Website 類中有一個 $name 屬性,我們可以在類中使用如下方法來訪問 $name 這個成員屬性:
$this -> name;
需要注意的是,在使用 $this 訪問某個成員屬性時,后面只需要跟屬性的名稱即可,不需要
$符號。另外,$this 只能在對象中使用,其它地方不能使用 $this,而且不屬于對象的東西 $this 也調(diào)用不了,可以說沒有對象就沒有 $this。
【示例】使用 $this 調(diào)用類中的屬性和方法。
name = $name;
$this -> name();
}
public function name(){
echo $this -> name.'
';
$this -> url();
}
public function url(){
echo 'http://c.biancheng.net/php/
';
$this -> title();
}
public function title(){
echo 'PHP入門教程
';
}
}
$object = new Website('C語言中文網(wǎng)');
?>
運行結(jié)果如下:
C語言中文網(wǎng)
http://c.biancheng.net/php/
PHP入門教程
文章名稱:PHP$this:當(dāng)前對象
分享地址:http://www.dlmjj.cn/article/djshjhe.html


咨詢
建站咨詢
