PHP
  Home arrow PHP arrow The Basics of Serializing Objects in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

The Basics of Serializing Objects in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 32
    2006-06-06


    Table of Contents:
  • The Basics of Serializing Objects in PHP
  • Explaining the core concepts
  • Creating self-serializing objects
  • Creating self-saving objects

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    The Basics of Serializing Objects in PHP
    ( Page 1 of 4 )

    Object serialization in PHP is very easy, and can be used for a variety of different purposes. It can be used to perform some fairly complex operations, in fact. This article, the first of a three-part series, introduces you to object serialization and a number of the tasks for which you can put this approach to use.

    Introduction

    Anyone who has been using PHP object-oriented programming for a while knows that object serialization can be a useful approach, which can be utilized for different purposes. Whether certain objects need to be stored as a string representation of their methods and properties in a database table, or maintained “alive” across several HTTP requests via a session mechanism, in all these cases serialization, and its counterpart, unserialization, play an undoubtedly relevant role.

    Certainly one of the best things about serializing objects is its extreme ease to perform, trust me. Using the popular combination of “serialize()/unserialize()” PHP native functions, it is perfectly possible to get an object serialized and vice versa, during the execution of a PHP application, without the need to appeal to sophisticated programming techniques.

    The truth is that when it comes to serializing objects, PHP makes the whole process a no-brainer task. However, despite its ease, object serialization can be used in different situations, in order to perform more complex operations, such as making an object persist during different web pages, or taking advantage of the “__sleep()” and “__wakeup()” magic functions, which are called automatically when an object is serialized and unserialized respectively.

    As you can see, serializing objects in PHP is a very useful approach, which deserves at least a closer analysis. That’s why over the course of this three-part series,  I’ll take an in-depth look at the more relevant topics regarding the serialization of objects, starting out with the basics, and progressively introducing more advanced concepts, like using objects in sessions, and storing them in database tables.

    What should you expect from this series? By the end of it, you should be equipped with a decent knowledge of how to serialize/unserialize objects without losing their methods and properties during the transition, as well as constructing persisting and session objects, and much more.

    Having established the goals for this series, let’s introduce ourselves to the vast territory of object serialization in PHP. Let’s go!



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT