搜索

首页  >  问答  >  正文

PHP中的$this代表当前的类还是方法?

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

里面的$this代表的是整个类DBmodel,还是类方法delete ?

A _ Q _i_A _ Q _i_1236 天前1013

全部回复(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
  • 取消回复