Object update
This commit is contained in:
44
Etudiant.class.php
Normal file
44
Etudiant.class.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
12
script1.php
12
script1.php
@@ -1,2 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
echo "script 1";
|
require_once 'Etudiant.class.php';
|
||||||
|
|
||||||
|
echo "script 1";
|
||||||
|
|
||||||
|
$etudiant = new Etudiant("Week", "John", 40);
|
||||||
|
|
||||||
|
echo $etudiant->afficherInfo();
|
||||||
|
|
||||||
|
$etudiant->setNom("CENA");
|
||||||
|
|
||||||
|
echo $etudiant->afficherInfo();
|
Reference in New Issue
Block a user