regarding classes
| From: | Jack Dempsey | Date: | Tue, 08 May 2001 19:54:37 +0000 |
| Subject: | regarding classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-51969@lists.php.net to get a copy of this message | ||
i deleted the original message, but here's why your code wouldn't work:
you were using $this->$items...
drop the second $
try this:
<?
class Cart {
var $items; // Items in our shopping cart
function add_item ($id,$text) {
$this->items[$id] = $text;
}
function output($id){
echo $this->items[$id];
}
}
$c = new Cart();
$c->add_item(0,"zero");
$c->add_item(1,"one");
$c->add_item(2,"two");
$c->output(0);
$c->output(1);
$c->output(2);
?>
that should be what you're looking for
-jack