Skip to content

Instantly share code, notes, and snippets.

@MkLHX
Last active September 21, 2016 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MkLHX/5d4047b2a000b17f1569b19191eebe96 to your computer and use it in GitHub Desktop.
Save MkLHX/5d4047b2a000b17f1569b19191eebe96 to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', 1);
include 'personne.php';
// New instance of personne class
$personne1 = new Personne();
//Set instance properties
$personne1->setPersonne('Mickael','Lehoux','Orleans','26/06/1983');
//Get instance properties
echo 'Bonjour '.$personne1->getPersonne().'<br/>';
//Set address properties
$personne1->setAddress('Orleans');
//Get address properties
echo 'tu habites à '.$personne1->getAddress().'<br/>';
echo 'tu as '.$personne1->age().' ans';
?>
<?php
class Personne {
private $firstName;
private $lastName;
private $address;
private $dateOfBirth;
// Setter
public function setPersonne ($firstName,$lastName,$address,$dateOfBirth){
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->address = $address;
$this->dateOfBirth = $dateOfBirth;
}
//Getter
public function getPersonne (){
return $this->firstName.'|'.$this->lastName.'|'.$this->address.'|'.$this->dateOfBirth;
}
public function setAddress ($address){
$this -> address = $address;
}
public function getAddress (){
return $this -> address;
}
public function age(){
$tabDate = explode('/',$this->dateOfBirth);
$birth = new DateTime($tabDate[2]);
$now = new DateTime();
$age = $now->diff($birth);
return $age->y;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment