Bonjour
Jusque là en php je programmais en procédural, mais j'aimerais exploiter à fond ce language, alors je me lance dans l'objet.Le passage est un peu déconcertant.
J'apprends en créant des scripts anodins, et je bloque sur le premier..
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php class commande { public $client_nom; public $client_prenom; public $contenu; public function create($nom, $prenom) { $this->client_nom = $nom; $this->client_prenom = $prenom; } public function addPizza($pizza, $quantite) { switch($pizza) { case marguerite: $this->contenu[0] = $quantite; break; case royale: $this->contenu[1] = $quantite; break; } } } $commande = new commande(); $commande->create($_GET['nom'], $_GET['prenom']); if($_GET['commander']) { $com = explode("-", $_GET['commander']); $commande->addPizza($com[0], $com[1]); } echo <<<EOT $commande->client_prenom $commande->client_nom a commandé $commande->contenu[0] marguerites et $commande->contenu[1] royales <br>Miam ! EOT; ?>
Mon problème est sur l'array $contenu. Le résultat m'affiche Array[0] et Array[1]. Alors ma question est pourquoi?







Répondre avec citation







! Cela viole l'encapsulation. Donc tu passes ça en private et tu mets des getter/setter : 
Partager