diff --git a/Etudiant.class.php b/Etudiant.class.php new file mode 100644 index 0000000..43c6589 --- /dev/null +++ b/Etudiant.class.php @@ -0,0 +1,44 @@ +nom = $nom; + $this->prenom = $prenom; + $this->age = $age; + } + + public function getNom() { + return $this->nom; + } + + public function getPrenom() { + return $this->prenom; + } + + public function getAge() { + return $this->age; + } + + public function setNom($nom) { + $this->nom = $nom; + } + + public function setPrenom($prenom) { + $this->prenom = $prenom; + } + + public function setAge($age) { + if ($age > 0) { + $this->age = $age; + } else { + throw new Exception("L'âge doit être un nombre positif."); + } + } + + public function afficherInfo() { + return "Nom: " . $this->nom . ", Prénom: " . $this->prenom . ", Âge: " . $this->age; + } + } \ No newline at end of file diff --git a/script1.php b/script1.php index f8c01cd..45cb988 100644 --- a/script1.php +++ b/script1.php @@ -1,2 +1,12 @@ afficherInfo(); + + $etudiant->setNom("CENA"); + + echo $etudiant->afficherInfo(); \ No newline at end of file