I am trying to persist a large class called an Authorizer which holds a reference to a database connection and a container of other objects representing the result of a complicated set of database queries. I want to serialize the expensive to build parts of this object in a session. Then when I need to ask the Authorizer a question I want to wake the Authorizer object up instead of building a new one for each page. I am writing a custom handler to temporarily store this object in a database table. I understand that the magic method __sleep() is usually used to handle choosing which parts of the object to store and then __wakeup() is used to restore the database connection.
This is where I get fuzzy. I think serialize() and unserialize() are supposed to work instead of the constructor and destructor, but I can't quite understand how they interact with __sleep() and __wakeup(). Then I got to the part of the manual describing the serializable interface and thought OK I will be able to implement this and be sure I have this right. Then I read that classes which implement this interface no longer support __sleep() and __wakeup()! That was the only part of this whole thing I really understood >:-{ I couldn't find any examples at all of how to properly implement this interface.
So my question is what is the preferred way to implement serialization in a completely object oriented system? Is the serializable interface meant to replace an older method? What is the purpose of having two different sets of functions (_sleep()/_wakeup() and serialize()/unserialize())?