when you reference a property of a class you don't need to say it's a
variable,
so use $this->item[] instead of $this->$items[$id] and it works okay. I
haven't quite worked out why it went wrong in the way it did ... and that'll
worry me until I do.
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Stefan Kostopoulos [mailto:[EMAIL PROTECTED]]
> Sent: 08 May 2001 20:31
> To: [EMAIL PROTECTED]
> Subject: Classes and arrays
>
>
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]