RE: [PHP] Inherited Arrays within objects problem.

From: Date: Sat, 23 Dec 2000 13:53:02 +0000
Subject: RE: [PHP] Inherited Arrays within objects problem.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31674@lists.php.net to get a copy of this message
Sorry, no, the code I provided is an example of what I'm trying to do. I didn't actually compile it and now looking at it, yes, it would throw errors. It was just meant to illustrate the concept that if I define the array in one and instantiate two, I can add but don't seem to be able to remove items from the array. I've even tried building a new array and overwriting the array. inside the method removeItems, everything seems to be fine but once the method ends, the array reverts back to it's original contents. Sorry for the confusion. Cal -----Original Message----- From: Cynic [mailto:cynic@mail.cz] Sent: Saturday, December 23, 2000 7:50 AM To: Cal Evans; php-general@lists.php.net Subject: RE: [PHP] Inherited Arrays within objects problem. Say what? It works on you machine? well, then I don't get how it could do _anything_. I had to change $this->myArray($name)=$stuff; to $this->myArray[$name]=$stuff; ^ ^ ^ ^ to get rid of a parse error. Then I got another one on unset($this-myArray($name)); adding the omitted > helped. ^^ Then I got another parse error at unset($this->myArray($name)); ^ ^ which is the same problem. Without those three bugs, the code worked. At 14:33 23.12. 2000, Cal Evans wrote the following: -------------------------------------------------------------- >No, the actual code part of a shopping cart I'm building. > >Cal > >-----Original Message----- >From: Cynic [mailto:cynic@mail.cz] >Sent: Friday, December 22, 2000 11:16 PM >To: Cal Evans; php-general@lists.php.net >Subject: Re: [PHP] Inherited Arrays within objects problem. > > >Ok, I assume that _wasn't_ actual code, was it? It throws up >a parse error on myArray($name) and on $this-myArray($name) >(of course: should be $this->myArray[$name] ). > >And, as far as my computer is concerned, this works (of course): > >class one >{ > function one(){ > $this->myArray = array(); > } > > function addRow($name,$stuff){ > $this->myArray[$name]=$stuff; > } > > function removeRow($name){ > unset($this->myArray[$name]); > } >} > >class two extends one >{ > function two(){ > $this->one(); > } >} > >$x = new two() ; >var_dump( $x ) ; >$x->addrow( 'offset' , 'data' ); >var_dump( $x ) ; >$x->removerow( 'offset' ) ; >var_dump( $x ) ; > >output is: > > > >At 06:03 23.12. 2000, Cal Evans wrote the following: >-------------------------------------------------------------- >>I'm seriously confused. >> >>I have two classes: >> >>class one { >> function one(){ >> $this->myArray = array(); >> } >> >> function addRow($name,$stuff){ >> $this->myArray($name)=$stuff; >> } >> >> function removeRow($name){ >> unset($this-myArray($name)); >> } >>} >> >>class two extends one{ >> >> function two(){ >> $this->one(); >> } >> >>} >> >>Now if I instantiate one, I can add and remove rows form the array. If I >>instantiate two, I can add rows but never remove them. I've tried >>array_splice and unset. within the function two->removeRow() the count >drops >>by one but once I'm outside of the function, it goes back to the original >>size. >> >>Anyone got ANY idea what I'm doing wrong here? >>TIA, >>Cal >> >>* >>* Professional Nerd Herder >>* http://www.calevans.com >>* >> >> >>-- >>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 >------end of quote------ > > > >____________________________________________________________ >Cynic: > >A member of a group of ancient Greek philosophers who taught >that virtue constitutes happiness and that self control is >the essential part of virtue. > >cynic@mail.cz > > > > >-- >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 ------end of quote------ ____________________________________________________________ Cynic: A member of a group of ancient Greek philosophers who taught that virtue constitutes happiness and that self control is the essential part of virtue. cynic@mail.cz

« previous php.general (#31674) next »