Re: Class var not retaining values

From: Date: Tue, 22 May 2001 13:15:36 +0000
Subject: Re: Class var not retaining values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53853@lists.php.net to get a copy of this message
Is the class variable declared as an array? class test{ var $reasons = array(); function addReason( $score, $reason, $id ) { $reasons[ $index ] = "$score|$reason|$id"; } } Hope this helps, -C ""Bob"" <bstremel@optonline.net> wrote in message news:9ec2rm$etg$1@toye.p.sourceforge.net... > I have a class defined with a var $reasons that I will use as an array. The > code to add to it is: > > function AddReason($score, $reason, $id) > { > static $index = 0; > $this->reasons[$index] = "$score|$reason|$id"; > for ($i = 0; $i < $index; $i++) > { > $out = $this->reasons[$i]; > echo "$out..."; > } > $index++; > return $score; > } > > However, every time I call it, the value stored in the reasons array seems > to disappear, and the array holds no data. It seems to be behaving like a > local variable, even though it is in a class. Any suggestions would be > greatly appreciated. > > Thanks > > > > -- > 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 >

« previous php.general (#53853) next »