Last active
September 21, 2016 09:08
-
-
Save MkLHX/5d4047b2a000b17f1569b19191eebe96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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