Re: issues with __sleep() and __wakeup()

From: Date: Tue, 31 Jul 2001 20:48:48 +0000
Subject: Re: issues with __sleep() and __wakeup()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60510@lists.php.net to get a copy of this message
on 7/31/01 1:48 PM, scott [gts] at scott@graphictype.com wrote: > I am having a problem with __sleep(); > there mere existance of it is causing my object > to not get serialized at all. __wakeup() works fine. > > i am using PHP v4.0.6 / apache / win2k. > > If i keep __sleep() in the object, it will not serialize, > but if i remove it, it serialized fine. Does anyone > know why this happens? i asked this about a month ago and didn't hear anything. i too have never been able to get __sleep to work. i think it's because i couldn't figure out what needed to be returned (or how to return it :) at http://www.php.net/manual/en/language.oop.magic-functions.php it says that __sleep is "supposed to return an array with the names of all variables of that object that should be serialized", but there are no examples of this. in a current project, i have an object that is registed as a session variable. it contains three objects and an array. one of the objects is a PEAR db object, and i don't need to serialize it. i do want to maintain the other two objects and the array. i tried a number of ideas inside __sleep, to no avail. without __sleep, it works. with __sleep, i break it. i do use __wakeup to reinitialize my db object, but i just use $db->disconnect(); at the end of my index file to disconnect . does anyone know the proper way to "clean up the object" in __sleep and how to return the variables that should be serialized? can this even be used when one (or more) of the variables is an object itself? thanks, mike -- mike cullerton

« previous php.general (#60510) next »