Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $this mean in PHP? [duplicate]

Possible Duplicate:
PHP: self vs this

Hello, Could you help me understanding the meaning of the PHP variable name $this?

Thank you for your help.

like image 609
Xela C Avatar asked Nov 08 '10 14:11

Xela C


People also ask

What does $This means in PHP?

$this is a reserved keyword in PHP that refers to the calling object. It is usually the object to which the method belongs, but possibly another object if the method is called statically from the context of a secondary object. This keyword is only applicable to internal methods.

What does &$ mean in PHP?

passing argument through reference (&$) and by $ is that when you pass argument through reference you work on original variable, means if you change it inside your function it's going to be changed outside of it as well, if you pass argument as a copy, function creates copy instance of this variable, and work on this ...

What does AT symbol mean in PHP?

The at sign (@) is used as error control operator in PHP.


1 Answers

$this refers to the class you are in.

For example

Class Car {

    function test() {
        return "Test function called";
    }

    function another_test() {
        echo $this->test(); // This will echo "Test function called";
    }
}

Hope this helps.

like image 154
jodm Avatar answered Oct 17 '22 05:10

jodm