Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Person
  5.  *
  6.  * Represents a person
  7.  */
  8. class Person
  9. {
  10.     const FORENAME = 'forename';
  11.     const SURNAME = 'surname';
  12.  
  13.     /**
  14.      * The person's forename
  15.      *
  16.      * @var string
  17.      * @access private
  18.      */
  19.     private $forename;
  20.  
  21.     /**
  22.      * The person's surname
  23.      *
  24.      * @var string
  25.      * @access private
  26.      */
  27.     private $surname;
  28.  
  29.     /**
  30.      * __construct
  31.      *
  32.      * @param string $forename the person's forename
  33.      * @param string $surname the person's surname
  34.      * @access public
  35.      * @return void
  36.      */
  37.     public function __construct($forename, $surname)
  38.     {
  39.         $this->setForename($forename);
  40.         $this->setSurname($surname);
  41.     }
  42.  
  43.     /**
  44.      * Set the forename
  45.      *
  46.      * @param string $forename the person's forename
  47.      * @access public
  48.      * @return void
  49.      */
  50.     public function setForename($forename)
  51.     {
  52.         $this->forename = (string) $forename;
  53.     }
  54.  
  55.     /**
  56.      * Set the surname
  57.      *
  58.      * @param string $surname the person's surname;
  59.      * @access public
  60.      * @return void
  61.      */
  62.     public function setSurname($surname)
  63.     {
  64.         $this->surname = (string) $surname;
  65.     }
  66.  
  67.     /**
  68.      * Get the person's forename
  69.      *
  70.      * @access public
  71.      * @return string
  72.      */
  73.     public function getForename()
  74.     {
  75.         return $this->forename;
  76.     }
  77.  
  78.     /**
  79.      * Get the person's surname
  80.      *
  81.      * @access public
  82.      * @return string
  83.      */
  84.     public function getSurname()
  85.     {
  86.         return $this->surname;
  87.     }
  88. }
  89.  
  90. $ibuildingsPeople = array();
  91. $ibuildingsPeople[] = new Person('Yair', 'Spitzer');
  92. $ibuildingsPeople[] = new Person('Gordon', 'Skinner');
  93. $ibuildingsPeople[] = new Person('Paul', 'Matthews');
  94.  
  95. sortPeople($ibuildingsPeople);
  96.  
  97. /**
  98.  * Sorts People by property
  99.  *
  100.  * @param array $people of Person objects
  101.  * @param string $property the property of Person to search on
  102.  * @access public
  103.  * @return array the sorted array of People
  104.  */
  105. function sortPeople($people, $property = Person::SURNAME)
  106. {
  107.     // your code here...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement