Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


What is the difference between self and $this in PHP5?

Damian99Damian99 USAMember Posts: 116

Can someone please explain the difference between using self and $this and what are the scenarios that each of these used?



  • DavidMDavidM USAMember Posts: 342

    This page says.

    Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members.

  • PHPProManPHPProMan Viet NamMember Posts: 5

    $this refers to the current object, self refers to the current class. The class is the blueprint of the object. So you define a class, but you construct objects.

    So in other words, use self for static and this for none-static members or methods.

Sign In or Register to comment.