Introduction to Zend Framework

 Learning Zend Framework


 Zend Framework Reference

  •  Zend_Gdata
  •  Zend_Http
  •  Zend_InfoCard
  •  Zend_Json
  •  Zend_Layout
  •  Zend_Ldap
  •  Zend_Loader
  •  Zend_Locale
  •  Zend_Log
  •  Zend_Mail
  •  Zend_Markup
  •  Zend_Measure
  •  Zend_Memory
  •  Zend_Mime
  •  Zend_Navigation
  •  Zend_Oauth
  •  Zend_OpenId
  •  Zend_Paginator
  •  Zend_Pdf
  •  Zend_ProgressBar
  •  Zend_Queue
  •  Zend_Reflection
  •  Zend_Registry
  •  Zend_Rest

  •  Zend_Search_Lucene
  •  Zend_Serializer
  •  Zend_Server
  •  Zend_Service
  •  Zend_Session
  •  Zend_Soap
  •  Zend_Tag
  •  Zend_Test
  •  Zend_Text
  •  Zend_TimeSync
  •  Zend_Tool
  •  Zend_Tool_Framework
  •  Zend_Tool_Project
  •  Zend_Translate
  •  Zend_Uri
  •  Zend_Validate
  •  Zend_Version
  •  Zend_View
  •  Zend_Wildfire
  •  Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Update 2011-11-16 - Revision 24438 - Version ZF 1.11.x

    Chapter 61. Zend_Serializer

    61.1. Introduction

    Zend_Serializer provides an adapter based interface to simply generate storable representation of PHP types by different facilities, and recover.

    Example 61.1. Using Zend_Serializer dynamic interface

    To instantiate a serializer you should use the factory method with the name of the adapter:

    $serializer Zend_Serializer::factory('PhpSerialize');
    // Now $serializer is an instance of Zend_Serializer_Adapter_AdapterInterface,
    // specifically Zend_Serializer_Adapter_PhpSerialize

    try {
    $serialized $serializer->serialize($data);
    // now $serialized is a string

    $unserialized $serializer->unserialize($serialized);
    // now $data == $unserialized
    } catch (Zend_Serializer_Exception $e) {

    The method serialize() generates a storable string. To regenerate this serialized data you can simply call the method unserialize().

    Any time an error is encountered serializing or unserializing, Zend_Serializer will throw a Zend_Serializer_Exception.

    To configure a given serializer adapter, you can optionally add an array or an instance of Zend_Config to the factory() or to the serialize() and unserialize() methods:

    $serializer Zend_Serializer::factory('Wddx', array(
    'comment' => 'serialized by Zend_Serializer',

    try {
    $serialized $serializer->serialize(
    'comment' => 'change comment')

    $unserialized $serializer->unserialize(
    /* options for unserialize */)
    } catch (
    Zend_Serializer_Exception $e) {

    Options passed to the factory() are valid for the instantiated object. You can change these options using the setOption(s) method. To change one or more options only for a single call, pass them as the second argument to either the serialize() or unserialize() method.

    Example 61.2. Using the Zend_Serializer static interface

    You can register a specific serializer adapter as a default serialization adapter for use with Zend_Serializer. By default, the PhpSerialize adapter will be registered, but you can change this option using the setDefaultAdapter() static method.

    // or
    $serializer Zend_Serializer::factory('PhpSerialize'$options);

    try {
    $serialized   Zend_Serializer::serialize($data$options);
    $unserialized Zend_Serializer::unserialize($serialized$options);
    } catch (
    Zend_Serializer_Exception $e) {

    digg delicious meneame google twitter technorati facebook