$this in PHP class
A _ Q _i_
A _ Q _i_ 2021-10-10 19:59:11
0
5
786
class DBmodel{ private $name; public __construct(){ $this->name = $name; } public function delete($name){ $this->name = $name; } }

Does $this in __construct represent __construct itself? Does $this in delete represent delete itself? Or does $this represent the entire class?

A _ Q _i_
A _ Q _i_

reply all (3)
hbxncjs

$this represents the entire class

    yntdx

    This object must be allocated using the new operator (not new[], not placement new, not a local object, not a global object); after deleting this, you cannot access any members of the object Variables and virtual functions (delete this recycles data, which includes the object's data members and vtable, excluding function code); after deleting this, the this pointer can no longer be accessed. In other words, you can't check it, compare it to other pointers, compare it to NULL, print it, convert it, or anything else

      逆旅行人

      $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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!