Re: Problem with Associative Array in Class
| From: | Marco Roccioletti | Date: | Mon, 13 Nov 2000 14:13:52 +0000 |
| Subject: | Re: Problem with Associative Array in Class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24962@lists.php.net to get a copy of this message | ||
Hi!
On Mon, 13 Nov 2000, Lon Baker wrote:
> A question:
>
> I placed an associated array in a class and during when adding new elements to the array
> nothing happened. The initial element kept being reset with the new key and value. Once I moved it
> outside the class everything was fine. Anyone have any ideas?
>
> Here is the code:
>
> // class for managing data parsedclass Spif { var $spifValues = array(); function setVar($what,
> $value) { $this->$spifValues[$what] = $value; } function getVar($what) { return
> $this->$spifValues[$what]; } function printVars() { echo count($this->$spifValues); }}
>
> <-snip->
>
> Calls the the class happened as sush:
>
> $newSpif->SetVar('info_checksum', $data);
>
> Every time print vars was called at the end the size came back a 1.
try with
$this->spifValues[$what] = $value; // without '$' after '->'
and NOT
$this->$spifValues[$what] = $value;
Cheers,
Marco