Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. class Personne{
  4.  
  5. public $_nom = 'Jones';
  6. public $_prenom = 'Bridget';
  7. public $_adresse = '1 rue des Fermettes';
  8. public $_datenaissance = [17, 10, 1989];
  9. private $_annee = '2016';
  10.  
  11. //méthode pour afficher les infos
  12. public function afficherInfos (){
  13.  
  14. return $this->_nom . '<br />'
  15. . $this->_prenom . '<br />'
  16. . $this->_adresse . '<br />'
  17. . $this->_datenaissance[0] . '/' . $this->_datenaissance[1] . '/'
  18. . $this->_datenaissance[2] . '<br/>';
  19. }
  20.  
  21. //méthode pour pouvoir changer l'adresse
  22. public function changerAdresse ($nouvelleAdresse) {
  23.  
  24. $this->_adresse = $nouvelleAdresse;
  25. return $this->_adresse;
  26. }
  27.  
  28. //méthode pour calculer l'âge
  29. public function calculAge() {
  30.  
  31. $age = $this->_annee - $this->_datenaissance[2];
  32. return $age . 'ans';
  33. }
  34. }
  35.  
  36. //instanciation des objets
  37. $bridget = new Personne;
  38. echo $bridget->afficherInfos();
  39. $bridget->changerAdresse('300 Avenue de la Gloire');
  40. echo $bridget->afficherInfos();
  41. echo $bridget->calculAge();
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement