搜尋

首頁  >  問答  >  主體

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

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

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

A _ Q _i_A _ Q _i_1218 天前1007

全部回覆(5)我來回復

  • autoload

    autoload2021-10-11 09:34:18

    $this代表的是對象,而$this所在環境為類別內部的方法內部,所以$this物件是在類別內部存取

    回覆
    0
  • A _ Q _i_

    A _ Q _i_2021-10-10 19:56:16

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

    裡面的$this代表的就是建構方法本身嗎?

    回覆
    0
  • autoload

    $this->name 代表的是這個類別中的name屬性

    autoload · 2021-10-14 09:49:31
  • 取消回覆