Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Person
- *
- * Represents a person
- */
- class Person
- {
- const FORENAME = 'forename';
- const SURNAME = 'surname';
- /**
- * The person's forename
- *
- * @var string
- * @access private
- */
- private $forename;
- /**
- * The person's surname
- *
- * @var string
- * @access private
- */
- private $surname;
- /**
- * __construct
- *
- * @param string $forename the person's forename
- * @param string $surname the person's surname
- * @access public
- * @return void
- */
- public function __construct($forename, $surname)
- {
- $this->setForename($forename);
- $this->setSurname($surname);
- }
- /**
- * Set the forename
- *
- * @param string $forename the person's forename
- * @access public
- * @return void
- */
- public function setForename($forename)
- {
- $this->forename = (string) $forename;
- }
- /**
- * Set the surname
- *
- * @param string $surname the person's surname;
- * @access public
- * @return void
- */
- public function setSurname($surname)
- {
- $this->surname = (string) $surname;
- }
- /**
- * Get the person's forename
- *
- * @access public
- * @return string
- */
- public function getForename()
- {
- return $this->forename;
- }
- /**
- * Get the person's surname
- *
- * @access public
- * @return string
- */
- public function getSurname()
- {
- return $this->surname;
- }
- }
- $ibuildingsPeople = array();
- $ibuildingsPeople[] = new Person('Yair', 'Spitzer');
- $ibuildingsPeople[] = new Person('Gordon', 'Skinner');
- $ibuildingsPeople[] = new Person('Paul', 'Matthews');
- sortPeople($ibuildingsPeople);
- /**
- * Sorts People by property
- *
- * @param array $people of Person objects
- * @param string $property the property of Person to search on
- * @access public
- * @return array the sorted array of People
- */
- function sortPeople($people, $property = Person::SURNAME)
- {
- // your code here...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement