Hi, Friday, April 23, 2004, 1:00:34 PM, you wrote: DN> I'm having a problem using classes. The problem stemed from DN> using arrays to store a bunch of users and their usage times.
DN> I have an object with two members, $name and $onlineSecs. No DN> matter how hard I try...$name always gets modified. I try DN> referencing $onlineSecs directly...I've tried writing mod DN> functions. I cannot stop the problem. DN> Here is a simplified code chunk (the echo's are for debugging): DN> <?php DN> class someuser{ DN> var $name; DN> var $onlineSecs; DN> function someuser(){ DN> echo "Default constructor<BR>\n"; DN> $this->$name = 'Some Name'; DN> echo "name: ".$this->$name."<BR>\n"; DN> $this->$onlineSecs = 0; DN> echo "name: ".$this->$name."<BR>\n"; DN> echo "ontime: ".$this->$onlineSecs."<BR>\n"; DN> } DN> } DN> $bob = new someuser; DN> echo "Bob's Name: ".$bob->$name."<BR>\n"; DN> echo "Bob's ontime: ".$bob->$onlineSecs."<BR>\n"; ?>> DN> It produces the following output: DN> Default constructor<BR> DN> name: Some Name<BR> DN> name: 0<BR> DN> ontime: 0<BR> DN> Bob's Name: 0<BR> DN> Bob's ontime: 0<BR> DN> However...all the Names should be "Some name". Can someone DN> please explain to me what dumb mistake I've made becuase I'm DN> tearing my hair out over something so simple! DN> Thank you, DN> Dickon... You are accessing the members incorrectly change echo "Bob's Name: ".$bob->$name."<BR>\n"; to echo "Bob's Name: ".$bob->name."<BR>\n"; PHP will try to substitute $bob and will end up with null which is not what you want. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php