session_register and class variables

From: Date: Tue, 22 Jan 2002 05:25:30 +0000
Subject: session_register and class variables
Groups: php.general 
Request: Send a blank email to php-general+get-81484@lists.php.net to get a copy of this message
Hi All, I am having problems with a class and session_register(). I define a class (parital implimentation below) with some variables and call session_register at the top of each page. After I change pages, I end up with all three variables containing the data from szAffiliateName. I have tried using the __sleep() function thus: function __sleep() { return array('szAffiliateName', 'szAffiliateImagePath', 'm_iAffiliateID'); } and it just seems to break everything. I noticed that there is also a post in the anotated manual which describes the problem (unfortunately there was not a following solution :) Any ideas would be appreciated. Cheers, Brad. class CAffiliate { // constructor function CAffiliate() { $szAffiliateName = ""; $szAffiliateImagePath = ""; $m_iAffiliateID = 0; } // "private" data memebers var $szAffiliateName; var $m_iAffiliateID; var $szAffiliateImagePath; . . . snip . . . function GetAffiliateName() { return $this->$szAffiliateName; } function GetAffiliateImagePath() { return "images/" . $this->$szAffiliateImagePath . "/"; } function GetAffiliateID() { return $this->$m_iAffiliateID; } } Regards, Brad From the annotated reference: I've been trying to do session_register with a test page and it keeps taking the last value of the last variable assigned a value in the class and making others that way. so for example if you do a: $SomeClass->varone = "Something"; $SomeClass->vartwo = "Nothing"; if you do a: session_register("SomeClass"); on the next page when you do an echo $SomeClass->$varone; echo $SomeClass->$vartwo; it will print out the value of $SomeClass->$vartwo twice. I dont know if this is just something I did wrong, but this is what I'm getting.

« previous php.general (#81484) next »