$this keyword refers to the instance from within the class definition : this « Class « PHP






$this keyword refers to the instance from within the class definition

 
<?php
  class Bird
  {
    function __construct($name, $breed)
    {
      $this->name = $name;
      $this->breed = $breed;
    }
  }

  $tweety = new Bird('Tweety', 'canary');

  printf("<p>%s is a %s.</p>\n", $tweety->name, $tweety->breed);
?>
  
  








Related examples in the same category

1.Use this keyword to reference interal properties
2.Use this keyword
3.Accessing the $age variable using this->