Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Introduction PHP orientation Objet
<?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';
<?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
You can’t perform that action at this time.