Use this keyword : this « Class « PHP






Use this keyword


<?php
   class Staff
   {
      var $name;
      var $city;
      protected $wage;

      function __get($propName)
      {
         echo "__get called!<br />";
         $vars = array("name","city");
         if (in_array($propName, $vars))
         {
            return $this->$propName;
         } else {
            return "No such variable!";
         }
      }
   }

   $employee = new Staff();
   $employee->name = "Joe";
   echo $employee->name."<br/>";
   echo $employee->age;
?>
           
       








Related examples in the same category

1.Use this keyword to reference interal properties
2.$this keyword refers to the instance from within the class definition
3.Accessing the $age variable using this->