PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Remember, both sessions and objects need something before they can be used. And if you store object in the session then the class needs to exist before the session is started.
arborint wrote:Remember, both sessions and objects need something before they can be used. And if you store object in the session then the class needs to exist before the session is started.
dwnthk wrote:I am not sure why I don't need to create the $so2page before I can assign the object to it. It is the way of PHP does maybe?!
You create the object in the first script. You assign it into the $_SESSION superglobal array. So when the first script ends, PHP serialize()'s all the data in $_SESSION and writes the data to whatever datastore your session is using (to disk by default). For objects is saves the class name.
Then in the second script when you start the session it reads the data from the datastore and unserialize()'s it. If there is an object in the data it checks to see if the class is loaded and if it is, it fixes up the object just like new. If the class is not loaded it marks the object class as unknown.
Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "PageImp" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Program Files\Apache Group\Apache2\htdocs\test\pmc_test1.php on line 30
I did not do any serialize() function in my php. Is that because the php will do serialize() by itself?
After that, then I tried to add serialize() and unserialize() to my scripts, but it seems like serialize()/unserialize() only take string as the parameter. Is it correct?