Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. class Person
  2. {
  3.     private $firstname;
  4.     private $lastname;
  5.    
  6.     public function __construct($pFirstname, $pLastname)
  7.     {
  8.         $this->firstname = $pFirstname;
  9.         $this->lastname = $pLastname;
  10.     }
  11.  
  12.     public function __set($name, $value)
  13.     {
  14.         if(isset($this->$name))
  15.         {
  16.             $this->$name = $value;
  17.             return true;
  18.         }
  19.        
  20.         $error = "Error: __set property: " . $name . " not supported by class: " . __CLASS__ ;
  21.         throw new Exception($error);
  22.         return false;
  23.     }
  24.    
  25.     public function __get($name)
  26.     {
  27.         if(isset($this->$name))
  28.             return $this->$name;
  29.        
  30.         $error = "Error: __get property: " . $name . " not supported by class: " . __CLASS__ . ".";
  31.         throw new Exception($error);
  32.         return false;
  33.     }
  34.    
  35.     public function __toString()
  36.     {
  37.         return $this->firstname . " " . $this->lastname;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement