RE: Classes and arrays

From: Date: Wed, 09 May 2001 07:55:27 +0000
Subject: RE: Classes and arrays
Groups: php.general 
Request: Send a blank email to php-general+get-52046@lists.php.net to get a copy of this message
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:stefan@supernovainc.com] > Sent: 08 May 2001 20:31 > To: php-general@lists.php.net > 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); > > > ?> >

« previous php.general (#52046) next »