ArckMax
11/5/2018 - 12:48 PM

Solution quête WCS "Introduction PHP orienté Objet"

Solution quête WCS "Introduction PHP orienté Objet"

<?php

class Personne{

    private $nom;
    private $prenom;
    private $adresse;
    private $birthdate;

    function __construct($param_nom,$param_prenom,$param_adresse,$param_birthdate){
        $this->nom = $param_nom;
        $this->prenom = $param_prenom;
        $this->adresse = $param_adresse;
        $this->birthdate = $param_birthdate; 
    }


    public function afficherInfo(){
        echo "Nom : ", $this->nom, "Prénom : ", $this->prenom, "Adresse : ", $this->adresse, "Date de naissance : ", $this->birthdate;
    }

    public function changeAdresse($newAdresse){
        $this->adresse = $newAdresse;
    }

    public function afficherAge(){
        $age = (time() - strtotime($this->birthdate)) / 3600 / 24 / 365;
        echo round($age);
    }

}

$max = new Personne("Polopopop","Maxime","8 Rue de la Ouistiterie", "1992-10-13");

$max->afficherInfo();
$max->afficherAge();






?>