Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. class Personne {
  4.  
  5. public $nom;
  6. public $prenom;
  7. public $adresse;
  8. public $dateNaissance;
  9.  
  10. public function __construct($nom, $prenom, $adresse, $dateNaissance)
  11. {
  12. $this->nom = $nom;
  13. $this->prenom = $prenom;
  14. $this->adresse = $adresse;
  15. $this->dateNaissance = $dateNaissance;
  16. }
  17.  
  18. public function description ()
  19. {
  20. echo "Bonjour je m'appelle " . $this->prenom . " " . $this->nom . ", j'habite à " . $this->adresse . " et je suis né le " . $this->dateNaissance . ".";
  21. }
  22.  
  23. public function modifierAdresse($nouvelleAdresse)
  24. {
  25. $this->adresse = $nouvelleAdresse;
  26. }
  27.  
  28. public function afficherAge(){
  29. $date = $this->dateNaissance;
  30. $date = preg_replace("/\//", " ", $date);
  31. $date = explode(" ", $date);
  32. $age = date("Y") - $date[2];
  33. if((date("m") - $date[1])< 0){
  34. $age -= 1;
  35. }
  36. echo "J'ai $age ans";
  37. }
  38. }
  39.  
  40. $john = new Personne("Doe", "John", "Nantes", "29/12/1994");
  41.  
  42. $john->description();
  43. echo "<br>";
  44. $john->modifierAdresse("Paris");
  45. $john->description();
  46. echo "<br>";
  47. $john->afficherAge();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement