$this keyword in php

What is $this in php ?

$this keyword is used to approach to properties and methods within the class. You can achieve the properties and methods of the class using syntax.

         SYNTAX

$this->name;
$this->fruitDetails();

  • $this keyword always starts with “$” sign while the approached property and methods does not contains ‘$’ sign as illustrated above.

Let’s write a program to demonstrate $this with an example.

 

In this lesson we learnt how to use $this keyword to approach the properties and methods within the class scope.

Things to Remember

$this keyword is used to approach the properties and methods withing the class scope.

Leave a Reply

Your email address will not be published. Required fields are marked *