Home  >  Q&A  >  body text

Does $this in PHP represent the current class or method?

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

Does $this inside represent the entire class DBmodel, or the class method delete?

A _ Q _i_A _ Q _i_1103 days ago924

reply all(5)I'll reply

  • autoload

    autoload2021-10-11 09:34:18

    $this represents an object, and the environment where $this is located is inside the method inside the class, so the $this object is accessed inside the class

    reply
    0
  • A _ Q _i_

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

    Does $this in

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

    represent the constructor method itself?

    reply
    0
  • autoload

    $this->name represents the name attribute in this class

    autoload · 2021-10-14 09:49:31
  • Cancelreply