Object update

This commit is contained in:
Xeno-linux
2025-09-29 11:36:10 +02:00
parent 8938e22e1e
commit c716cd947d
2 changed files with 55 additions and 1 deletions

44
Etudiant.class.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
class Etudiant {
private $nom;
private $prenom;
private $age;
public function __construct($nom, $prenom, $age) {
$this->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;
}
}

View File

@@ -1,2 +1,12 @@
<?php
require_once 'Etudiant.class.php';
echo "script 1";
$etudiant = new Etudiant("Week", "John", 40);
echo $etudiant->afficherInfo();
$etudiant->setNom("CENA");
echo $etudiant->afficherInfo();