Created
September 27, 2018 08:56
-
-
Save Florencelg/a3230e4a30189fc9a1ff98baeae7ca1d to your computer and use it in GitHub Desktop.
Introduction PHP orientation Objet
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 | |
require 'Personnage.php'; | |
$Personne = new Personnage('Harry','Potter','Ecole des Sociers 45000 Orléans'); | |
$Personne->setDateTime(2008); | |
echo $Personne-> affichePersonne() . "<br/>"; | |
echo 'adresse:'.$Personne->getAdresse()."<br/>"; | |
echo 'adresse:'.$Personne->setAdresse('Dans ton cul LULU' )."<br/>"; | |
echo 'age:'.$Personne->calculAge(2008).' 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 Personnage{ | |
private $firstName; | |
private $lastName; | |
private $adresse; | |
private $dateTime; | |
public function __construct(string $firstName, string $lastName, string $adresse) | |
{ | |
$this->firstName = $firstName; | |
$this->lastName = $this->setLastName($lastName); | |
$this->adresse = $adresse; | |
} | |
/** | |
* @return string | |
*/ | |
public function getFirstName ():string | |
{ | |
return $this-> firstName; | |
} | |
/** | |
* @return string | |
*/ | |
public function getLastName():string | |
{ | |
return $this->lastName; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAdresse():string | |
{ | |
return $this->adresse; | |
} | |
/** | |
* @return int | |
*/ | |
public function getDateTime() | |
{ | |
return $this->dateTime; | |
} | |
/** | |
* @param string $firstName | |
*/ | |
public function setFirstName(string $firstName) | |
{ | |
$this->firstName = $firstName; | |
} | |
/** | |
* @param string $lastName | |
*/ | |
public function setLastName(string $lastName) | |
{ | |
return $this->lastName = strtoupper( $lastName); | |
} | |
public function affichePersonne(){ | |
return 'Personne:'.$this->lastName .' '. $this->firstName .' '. $this->adresse .' '. $this-> dateTime . "<br/>"; | |
} | |
/** | |
* @param string $adresse | |
*/ | |
public function setAdresse(string $adresse) | |
{ | |
return $this->adresse = $adresse; | |
} | |
/** | |
* @param datetime $dateTime | |
*/ | |
public function setDateTime($dateTime) | |
{ | |
$this->dateTime = $dateTime; | |
} | |
public function calculAge ($dateTime) | |
{ | |
$datActuelle= 2018; | |
$result= $datActuelle - $dateTime; | |
return $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment