Skip to content

Instantly share code, notes, and snippets.

@chraiet
Created February 16, 2017 21:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chraiet/f37715d9ba0bd0c92a85c409ab1eacd9 to your computer and use it in GitHub Desktop.
Save chraiet/f37715d9ba0bd0c92a85c409ab1eacd9 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: mchraiet
* Date: 16/02/17
* Time: 2:52 PM
*/
class Person
{
private $fname;
private $lname;
private $age;
// Unit: cm
private $height;
public function __construct($fname, $lname) {
$this->fname = $fname;
$this->lname = $lname;
}
/**
* SETTERS
*/
public function setFname($nFname) {
if (!is_null($nFname) && $nFname != "") {
$this->fname = $nFname;
} else {
throw new Exception("Le prénom ne doit pas être null et ne doit pas être vide.");
}
}
public function setLname($nLname) {
if (!is_null($nLname) && $nLname != "") {
$this->lname = $nLname;
} else {
throw new Exception("Le nom ne doit pas être null et ne doit pas être vide.");
}
}
public function setAge($nAge) {
if (!is_null($nAge) && $nAge >= 0) {
$this->age = $nAge;
} else {
throw new Exception("L'âge ne doit pas être null et doit être un nombre positif.");
}
}
public function setHeight($nHeight) {
if (!is_null($nHeight) && $nHeight >= 0) {
$this->height = $nHeight;
} else {
throw new Exception("La hauteur ne doit pas être null et doit être un nombre positif.");
}
}
/**
* GETTERS
*/
public function getFname() {
return $this->fname;
}
public function getLname() {
return $this->lname;
}
public function getAge() {
return $this->age;
}
public function getHeight() {
return $this->height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment