Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class human_template {
- /**
- * The humans name
- * @var string
- */
- protected $name;
- /**
- * The human sex
- * @var string
- */
- protected $sex;
- /**
- * The human age
- * @var integer
- */
- protected $age;
- /**
- * Returns the current population of the Human class
- * @return integere
- */
- static $population = 0;
- /**
- * Constructor, also set self::SetPopulation to +1 (human population)
- * @param type $name
- * @param type $age
- */
- function __construct($name, $age) {
- self::SetPopulation();
- $this->name = $name;
- $this->age = $age;
- }
- /**
- * Static function, that adds 1 to the current HUMAN population everytime an object is made fra abstract class
- */
- private static function SetPopulation() {
- human_template::$population++;
- }
- }
- // end of abstract class human_template
- /**
- * Man class based upon human_template abstract
- */
- class man extends human_template {
- /**
- * Declares the gender of the human
- * @var string
- */
- protected $sex = 'man';
- /**
- * Declares the current MAN population
- * @var integere
- */
- static $population = 0;
- /**
- * Calls the parent construct from abstract human_class
- * @param type $name
- * @param type $age
- */
- function __construct($name, $age) {
- parent::__construct($name, $age);
- self::$population++;
- }
- }
- /**
- * Calls the parent construct from abstract human_class
- * @param type $name
- * @param type $age
- */
- class woman extends human_template {
- /**
- * Sets the human gender to woman
- * @var String
- */
- protected $sex = 'woman';
- /**
- * Contains the current generated human womans.
- * @var integer
- */
- static $population = 0;
- /**
- * Calls the parent construct from abstract human_class
- * @param type $name
- * @param type $age
- */
- function __construct($name, $age) {
- parent::__construct($name, $age);
- self::$population++;
- }
- }
- $human1 = new woman('wendy', '19');
- $human2 = new man('jack', '21');
- print_r($human1);
- print_r($human2);
Add Comment
Please, Sign In to add comment