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;
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.