Created
October 23, 2018 14:41
-
-
Save Chojiu15/20f2c5331b9ba9bd3836aebbbdc2aa82 to your computer and use it in GitHub Desktop.
classe.php
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 "perso.php"; | |
$heroe = new Personne("azir", "boobl", "2009-05-11"); | |
$heroe->adresse("3 place des fleurs"); | |
$heroe->afficher(); | |
?> |
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{ | |
public $nom; | |
public $prénom; | |
public $adresse; | |
public $date_de_naissance; | |
public function adresse($adresse){ | |
$this->adresse = $adresse; | |
} | |
public function __construct($nom, $prénom, $date_de_naissance){ | |
$this->nom = $nom; | |
$this->prénom = $prénom; | |
$this->date_de_naissance = $date_de_naissance; | |
} | |
public function age(){ | |
$age = (time() - strtotime($this->date_de_naissance)) / 3600 / 24 / 365; | |
return $age; | |
} | |
public function afficher(){ | |
echo "je m'appelle $this->nom $this->prénom j'habite $this->adresse et j'ai ".$this->age().' ans'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment