Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Personne {
- public $nom;
- public $prenom;
- public $adresse;
- public $dateNaissance;
- public function __construct($nom, $prenom, $adresse, $dateNaissance)
- {
- $this->nom = $nom;
- $this->prenom = $prenom;
- $this->adresse = $adresse;
- $this->dateNaissance = $dateNaissance;
- }
- public function description ()
- {
- echo "Bonjour je m'appelle " . $this->prenom . " " . $this->nom . ", j'habite à " . $this->adresse . " et je suis né le " . $this->dateNaissance . ".";
- }
- public function modifierAdresse($nouvelleAdresse)
- {
- $this->adresse = $nouvelleAdresse;
- }
- public function afficherAge(){
- $date = $this->dateNaissance;
- $date = preg_replace("/\//", " ", $date);
- $date = explode(" ", $date);
- $age = date("Y") - $date[2];
- if((date("m") - $date[1])< 0){
- $age -= 1;
- }
- echo "J'ai $age ans";
- }
- }
- $john = new Personne("Doe", "John", "Nantes", "29/12/1994");
- $john->description();
- echo "<br>";
- $john->modifierAdresse("Paris");
- $john->description();
- echo "<br>";
- $john->afficherAge();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement