·  PHP – Syntax – Keywords – $this

 

- Info:

  - $this refers to the current object (instance of the class).

  - $this is used in non-static member functions, and is a reference to object on which the member function was called.

  - Because "$this" is an object, you use it like: $this->member.

  - This info is based http://stackoverflow.com/questions/151969/php-self-vs-this.

 

- Example:

  - Create PHP Console Application Test.php.

 

    Test.php

    <?php

   

      class MyClass {

        public $prop = "Property";

          public function myfunc() {

        print($this->prop);

        }

      }

   

      //REFERENCE

      $obj = new MyClass();

      print($obj->myfunc()."\n");

   

    ?>