Skip to content

Instantly share code, notes, and snippets.

@Jules59
Created March 22, 2018 14:06
Show Gist options
  • Save Jules59/5271729604ab185c71083d2e5d5949d3 to your computer and use it in GitHub Desktop.
Save Jules59/5271729604ab185c71083d2e5d5949d3 to your computer and use it in GitHub Desktop.
poo
<?php
class Personn
{
//Attributs
private $firstName;
private $lastName;
private $address;
private $birthDate;
//Methodes
public function __construct($firstName,$lastName,$address,$birthDate)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->address = $address;
$this->birthDate = $birthDate;
}
//Personn identity
public function getidentity()
{
return $this->firstName . '<br/>' . $this->lastName . '<br/>' . $this->address . '<br/>' . $this->birthDate;
}
//Modified Address
public function setaddress($modifaddress)
{
$this->address = $modifaddress;
}
//Modified birthDate
public function getbirthDate()
{
return $this->birthDate;
}
public function getdiffAge ($birthDate)
{
$from = new DateTime($birthDate);
$to = new DateTime('today');
$age = date_diff($from, $to)->y;
return $age;
}
}
$Personne= new Personn('Julien', 'Lemaire', 'Lille', '1989-09-11');
$Personne->setAddress("Bruges");
echo $Personne->getidentity() ,'<br/>';
echo $Personne->getdiffAge($Personne->getbirthDate()) . ' ans';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment