您的位置:首頁技術文章
文章詳情頁

PHP中的$this代表當前的類還是方法?

瀏覽:230日期:2022-06-01 13:01:21

問題描述

class DBmodel{ private $name; publice function delete($name){$this->name = $name; }}

里面的$this代表的是整個類DBmodel,還是類方法delete ?

問題解答

回答1:

$this代表的是對象,而$this所在環境為類內部的方法內部,所以$this對象是在類內部訪問

回答2:

//如果里面有構造方法:function __construct(){$this->name = $name;}

里面的$this代表的就是構造方法本身嗎?

国产综合久久一区二区三区