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

Howdy, Stranger!

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

Categories

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

Damian99Damian99 USAPosts: 116Member

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

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member

    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 NamPosts: 4Member

    $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.