-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuteur.php
47 lines (37 loc) · 1.34 KB
/
Auteur.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class auteur{
private $_nom; // underscore "_" pour différencier les méthodes des attributs
private $_prenom;
private $_livre;
public function __construct(string $prenom, string $nom ){
$this->_prenom = $prenom;
$this->_nom = $nom;
$this->_livre = []; //création d'un tableau prenant l'objet livre, l'ensembles des variables livres
}
public function getPrenom(){
return $this->_prenom;
}
public function getNom(){
return $this->_nom;
}
public function setPrenom(){
return $this->_prenom;
}
public function setNom(){
return $this->_nom;
}
public function setLivre(){
return $this->_livre;
}
public function ajouterLivre($nlivre){ //fonction pour rajouter de nouveaux livres
array_push($this->_livre, $nlivre); //empile un/plusieurs éléments du tableau
}
public function afficherBibliographie(){ //fonction pour afficher et se répéter pour chaques variables livres
foreach ($this->_livre as $livre){ //répétition de l'objet livre
echo $livre; //affichage de la ligne du tableau
}
}
public function __toString(){ //créé une représentation textuelle de l'objet
return "$this->_prenom $this->_nom";
}
}