Re: Classes and arrays
| From: | Wieger Uffink | Date: | Wed, 09 May 2001 13:35:27 +0000 |
| Subject: | Re: Classes and arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-52100@lists.php.net to get a copy of this message | ||
Hi,
write $this->items[$id] instead of $this->$items[$id]
bye
Wieger
Stefan Kostopoulos wrote:
>
> Hi!
>
> Can anybody explain to me why this script outputs:
>
> oneone
>
> instead of:
>
> zeroone
>
> ???????????
>
> Thanks,
>
> stefan
>
> <?
> 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->output(0);
> $c->output(1);
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Wieger Uffink
tel: +31 20 428 6868
fax: +31 20 470 6905
web: http://www.usmedia.nl