Home arrow PHP arrow Using the Sleep and Wakeup Functions to Serialize Objects in PHP

Using the Sleep and Wakeup Functions to Serialize Objects in PHP

Curious about how to serialize your objects inside your beautifully-crafted application? Look no further. Welcome to the second part of the series "Serializing objects in PHP." This set of three tutorials introduces the fundamentals of objects serialization, and teaches you some advanced concepts regarding this approach, such as using objects in sessions and storing them in database tables.

  1. Using the Sleep and Wakeup Functions to Serialize Objects in PHP
  2. A quick look at how to define self-saving objects
  3. Using the “__sleep()” and “__wakeup()” magic functions
  4. Creating persisting objects
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
June 13, 2006

print this article




As you'll surely recall, over the previous article, I explained the basics of serializing objects in PHP. I showed some code samples that illustrated in a simple way the process of converting objects to their string representation (called serialization). I also showed how to reverse this process (that is unserialization), in order to restore these objects to their original state. In the several examples that you saw before, I also exposed some interesting concepts involved in object serialization, such as constructing objects that are capable of saving and restoring themselves via their own methods, which are commonly called self-saving objects.

As a matter of fact, one of the best things about serializing objects in PHP is that this fairly simple concept can be used as the starting point to tackle more advanced concepts, including those related to an object's persistence and its storage in database tables. In addition, if you've been working with sessions for a while, then you'll know that the PHP built-in session handling mechanism serializes and unserializes objects behind the scenes, whenever they're registered during a particular session, which means that object serialization is indeed an important topic that must be addressed appropriately.

Now, after refreshing the concepts that I deployed in the first part of this series, it's time to focus on the topics that I'll cover in this article, so you'll know what to expect before you continue reading. In this second part, I'll explain how to use objects in conjunction with the "__sleep()" and "__wakeup() magic functions respectively, in order to get the most out of them.

Having defined the topics for this new tutorial, let's move on and continue learning more about object serializing in PHP. Let’s go!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: