Skip to content

Instantly share code, notes, and snippets.

@Ludovicmoreau
Created September 19, 2016 16:43
Show Gist options
  • Save Ludovicmoreau/0f64b82bf6706bbb2a98c48a2b865c5e to your computer and use it in GitHub Desktop.
Save Ludovicmoreau/0f64b82bf6706bbb2a98c48a2b865c5e to your computer and use it in GitHub Desktop.
<?php
class Personne{
public $nom = '';
public $prenom ='';
public $adresse = '';
public $datedenaissance = '';
public function __construct ( $nom, $prenom, $adresse, $datedenaissance){
$this->nom = $nom ;
$this->prenom = $prenom ;
$this->adresse = $adresse ;
$this->datedenaissance = $datedenaissance ;
}
public function affichePersonnage(){
return $this->nom.' '.
$this->prenom.' '.
$this->adresse.' '.
$this->datedenaissance;
}
public function nouvelleAdresse(){
return $this->adresse = 'BLA';
}
function Age(){
$this->datedenaissance = explode("/", $this->datedenaissance);
$age = (date("md", date("U", mktime(0, 0, 0, $this->datedenaissance[0], $this->datedenaissance[1], $this->datedenaissance[2]))) > date("md")
? ((date("Y") - $this->datedenaissance[2]) - 1)
: (date("Y") - $this->datedenaissance[2]));
echo "Age is:" . $age;
}
}
?>
<?php
require 'class.php' ;
$ludovic = new Personne('MOREAU', 'Ludovic', 'Orléans', '1994') ;
echo $ludovic->affichePersonnage();
echo $ludovic->nouvelleAdresse();
echo $ludovic->Age();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment