Bonjour. j'essaye d'ecrire un code dans php. Mais quand je lexecute il me donne l'erreur suivante:
Notice: Undefined offset: 0 in c:\program files\easyphp1-8\www\php\page1.php on line 27
Notice: Undefined offset: 1 in c:\program files\easyphp1-8\www\php\page1.php on line 30
Le code est le suivant:
Code : 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
37 <?php class Commande { var $prixRam = 6; var $prixHD = 8; var $nomClient; var $listemateriel; function Commande() { $this->nomClient = "SansNom"; } function ajouterRam($nombre) { $this->listemateriel[0] += $nombre; } function ajouterHD($nombre) { $this->listemateriel[1] += $nombre; } function calculerPrix() { $montant_Ram = $this->listemateriel[0] * $this->prixRam; $montant_HD = $this->listemateriel[1] * $this->prixHD; return $montant_Ram + $montant_HD; } function afficherCommande() { echo "Commande du client : ".$this->nomClient; echo "<BR>materiel(s) 'Ram' : ".$this->listemateriel[0]; echo "<BR>materiel(s) 'HD' : ".$this->listemateriel[1]; echo "<HR>Totale de votre commande : ".$this->calculerPrix(); echo " Euros<BR>"; } } $client1 = new Commande(); $client1->ajouterRam(5); $client1->ajouterHD(2); $client1->afficherCommande(); ?>






Répondre avec citation



Partager