Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. abstract class human_template {
  2.  
  3.     /**
  4.      * The humans name
  5.      * @var string
  6.      */
  7.     protected $name;
  8.  
  9.     /**
  10.      * The human sex
  11.      * @var string
  12.      */
  13.     protected $sex;
  14.  
  15.     /**
  16.      * The human age
  17.      * @var integer
  18.      */
  19.     protected $age;
  20.  
  21.     /**
  22.      * Returns the current population of the Human class
  23.      * @return integere
  24.      */
  25.     static $population = 0;
  26.  
  27.     /**
  28.      * Constructor, also set self::SetPopulation to +1 (human population)
  29.      * @param type $name
  30.      * @param type $age
  31.      */
  32.     function __construct($name, $age) {
  33.         self::SetPopulation();
  34.         $this->name = $name;
  35.         $this->age = $age;
  36.     }
  37.  
  38.     /**
  39.      * Static function, that adds 1 to the current HUMAN population everytime an object is made fra abstract class
  40.      */
  41.     private static function SetPopulation() {
  42.         human_template::$population++;
  43.     }
  44. }
  45.  
  46. // end of abstract class human_template
  47.  
  48. /**
  49.  * Man class based upon human_template abstract
  50.  */
  51. class man extends human_template {
  52.  
  53.     /**
  54.      * Declares the gender of the human
  55.      * @var string
  56.      */
  57.     protected $sex = 'man';
  58.  
  59.     /**
  60.      * Declares the current MAN population
  61.      * @var integere
  62.      */
  63.     static $population = 0;
  64.  
  65.     /**
  66.      * Calls the parent construct from abstract human_class
  67.      * @param type $name
  68.      * @param type $age
  69.      */
  70.     function __construct($name, $age) {
  71.         parent::__construct($name, $age);
  72.         self::$population++;
  73.     }
  74. }
  75.  
  76.     /**
  77.      * Calls the parent construct from abstract human_class
  78.      * @param type $name
  79.      * @param type $age
  80.      */
  81. class woman extends human_template {
  82.    
  83.     /**
  84.      * Sets the human gender to woman
  85.      * @var String
  86.      */
  87.     protected $sex = 'woman';
  88.    
  89.     /**
  90.      * Contains the current generated human womans.
  91.      * @var integer
  92.      */
  93.     static $population = 0;
  94.      
  95.     /**
  96.      * Calls the parent construct from abstract human_class
  97.      * @param type $name
  98.      * @param type $age
  99.      */
  100.     function __construct($name, $age) {
  101.         parent::__construct($name, $age);
  102.         self::$population++;
  103.     }
  104. }
  105.  
  106. $human1 = new woman('wendy', '19');
  107. $human2 = new man('jack', '21');
  108.  
  109. print_r($human1);
  110. print_r($human2);
Add Comment
Please, Sign In to add comment