document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. class Person
  3. {
  4.     private $_name;
  5.     private $_age;
  6.  
  7.     function __construct($name, $age = 0)
  8.     {
  9.         if (!is_int($age))
  10.         {
  11.             throw new Exception("Cannot assign non integer value to
  12.             integer field, \'Age\'");
  13.         }
  14.         $this->_age = $age;
  15.         $this->_name = $name;
  16.     }
  17.  
  18.     public function setAge($age)
  19.     {
  20.         if (!is_int($age))
  21.         {
  22.             throw new Exception("Cannot assign non integer value to
  23. integer field, \'Age\'");
  24.         }
  25.         $this->_age = $age;
  26.     }
  27.     public function yearsToRetire()
  28.     {
  29.         return 67 - $this->_age;
  30.     }
  31. }
  32. $person = new Person("Wes");
  33. $person->setAge(31);
  34. echo $person->yearsToRetire();
  35. ?>
');