A Class Is A Collection Of Variables And Functions Working With These Variables.

<?php
class Cart {
    var $items;
 
    function add_item ($artnr, $num) {
        $this->items[$artnr] += $num;
    }    function remove_item ($artnr, $num) {
        if ($this->items[$artnr] > $num) {
            $this->items[$artnr] -= $num;
            return true;
        } else {
            return false;
        }
    }
}
class Named_Cart extends Cart {
    var $owner;
    function set_owner ($name) {
        $this->owner = $name;
    }
}$ncart = new Named_Cart;
$ncart->set_owner ("kris");
print $ncart->owner;
$ncart->add_item ("10", 1);
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.