Guest User

Untitled

a guest
Oct 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Personne {
  4.  
  5. private $nom;
  6. private $prenom;
  7. private $adresse;
  8. private $birthDate;
  9.  
  10. public function __construct($nom, $adresse, $prenom, $birthDate) {
  11. $this->nom = $nom;
  12. $this->prenom = $prenom;
  13. $this->adresse = $adresse;
  14. $this->birthDate = $birthDate;
  15. }
  16.  
  17. public function infoPersonne() {
  18. echo $this->nom . " " . $this->prenom . " " . $this->adresse . " " . $this->getAge($this->birthDate);
  19. }
  20.  
  21. public function setAdresse($adresse) {
  22. $this->adresse = $adresse;
  23. }
  24.  
  25. private function getAge($birthDate) {
  26.  
  27. list($jour, $mois, $annee) = explode('/', $birthDate);
  28. $TSN = strtotime($annee . "/" . $mois . "/" . $jour);
  29. $TS = strtotime(date("Y/m/d"));
  30.  
  31. $Age = ($TS - $TSN) / (365 * 3600 * 24);
  32. return round($Age);
  33.  
  34. }
  35. }
  36.  
  37. $personne = new Personne("Thomas", "27 Avenue", "Lasky", "05/03/1998");
  38.  
  39. $personne->infoPersonne();
Add Comment
Please, Sign In to add comment