Re: Inherited Arrays within objects problem.

From: Date: Sat, 23 Dec 2000 05:26:28 +0000
Subject: Re: Inherited Arrays within objects problem.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31655@lists.php.net to get a copy of this message
oh well... the output is: object(two)(1) { ["myArray"]=> array(0) { } } object(two)(1) { ["myArray"]=> array(1) { ["offset"]=> string(4) "data" } } object(two)(1) { ["myArray"]=> array(0) { } } At 06:16 23.12. 2000, Cynic wrote the following: -------------------------------------------------------------- >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 (#31655) next »