Artikel A:
- Nummer: M728
- Naam: Muis
- Prijs: 6.95
- Voorraad: 50

U wilt 45 van dit artikel kopen.
Nu nog op voorraad: 5

De voorraad raakt op!

<?

class Artikel {
    
// klasse constanten
    
const MIN_VOORRAAD 10;
    const 
BEGIN_VOORRAAD 50;
    public static 
$aantal 0;
    public 
$id;
    public 
$naam;
    public 
$prijs;
    public 
$voorraad;
    
    public function 
__construct($art$nm$pr){
        
$this->artid $art;
        
$this->naam $nm;
        
$this->prijs $pr;
        
$this->voorraad self::BEGIN_VOORRAAD;
        
// teller
        
self::$aantal ++;
        }
    public function 
verkoop($x){
        
$tekst "U wilt $x van dit artikel kopen.</br>";
        if (
$this->voorraad $x) {
            
$tekst .= "Helaas hebben wij dit niet in voorraad.</br>";
        }
        else {
            
$this ->voorraad -= $x;
            
$tekst .= "Nu nog op voorraad: ".$this->voorraad."</br>";
            }
        if (
$this->voorraad self::MIN_VOORRAAD){
            
$tekst .= "<h3>De voorraad raakt op! </H3>";
            }
            return (
$tekst);
            }
        }

$art_A = new Artikel ("M728","Muis",6.95);
echo 
"Artikel A: </br>";
echo 
"- Nummer: ".$art_A->artid."</br>";
echo 
"- Naam: ".$art_A->naam."</br>";
echo 
"- Prijs: ".$art_A->prijs."</br>";
echo 
"- Voorraad: ".$art_A->voorraad."</br><hr>";

echo 
$art_A->verkoop(45);

 
show_source(__FILE__); 
?>