Salut,
Je fais des petits exos de class et j'aurai une question sur l'extends, en gros j'ai fait un systeme de commande vite fait, je passe deux commandes, nikel, j'aimerai ensuite avoir une class qui reprenne les commandes de l'autre pour en resortir le CA global de la commande.
QQun pourrait m'eclairer ?
Code :
- <?php
- class commande
- {
- var $produit;
- var $prix_produit = 12;
-
- function __construct($nom_client)
- {
- $this->nom_client = $nom_client;
- }
-
- function ajouter($nombre)
- {
- $this->produit[0] += $nombre;
- }
-
- function prix()
- {
- return $this->produit[0]*$this->prix_produit;
- }
-
- function afficher_commande()
- {
- echo 'Client : '.$this->nom_client;
- echo '<br>Total commande : '.$this->prix();
- }
- }
- class CA extends commande
- {
- function CA_global()
- {
- echo '<br><br>CA global : '.$this->prix();
- }
- }
- $commande = new CA("Jacky" );
- $commande->ajouter(5);
- $commande->afficher_commande();
- echo '<br><br>';
- $commande2 = new CA("Maurice" );
- $commande2->ajouter(14);
- $commande2->afficher_commande();
- ?>
|
Message édité par nycius le 24-08-2007 à 09:55:19