1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.serializer.adapter">
4 <title>Zend_Serializer_Adapter</title>
7 <classname>Zend_Serializer</classname> adapters create a bridge for different methods of
8 serializing with very little effort.
12 Every adapter has different pros and cons. In some cases, not every <acronym>PHP</acronym>
13 datatype (e.g., objects) can be converted to a string representation. In most such cases,
14 the type will be converted to a similar type that is serializable -- as an example,
15 <acronym>PHP</acronym> objects will often be cast to arrays. If this fails, a
16 <classname>Zend_Serializer_Exception</classname> will be thrown.
20 Below is a list of available adapters.
23 <sect2 id="zend.serializer.adapter.phpserialize">
24 <title>Zend_Serializer_Adapter_PhpSerialize</title>
27 This adapter uses the built-in <methodname>un/serialize</methodname>
28 <acronym>PHP</acronym> functions, and is a good default adapter choice.
32 There are no configurable options for this adapter.
36 <sect2 id="zend.serializer.adapter.igbinary">
37 <title>Zend_Serializer_Adapter_Igbinary</title>
40 <ulink url="http://opensource.dynamoid.com">Igbinary</ulink> is Open Source Software
41 released by Sulake Dynamoid Oy. It's a drop-in replacement for the standard
42 <acronym>PHP</acronym> serializer. Instead of time and space consuming textual
43 representation, igbinary stores <acronym>PHP</acronym> data structures in a compact
44 binary form. Savings are significant when using memcached or similar memory based
45 storages for serialized data.
49 You need the igbinary <acronym>PHP</acronym> extension installed on your system in order
54 There adapter takes no configuration options.
58 <sect2 id="zend.serializer.adapter.wddx">
59 <title>Zend_Serializer_Adapter_Wddx</title>
62 <ulink url="http://wikipedia.org/wiki/WDDX">WDDX</ulink> (Web Distributed Data eXchange)
63 is a programming-language-, platform-, and transport-neutral data interchange mechanism
64 for passing data between different environments and different computers.
68 The adapter simply uses the <ulink
69 url="http://php.net/manual/book.wddx.php">wddx_*()</ulink> <acronym>PHP</acronym>
70 functions. Please read the <acronym>PHP</acronym> manual to determine how you may enable
71 them in your <acronym>PHP</acronym> installation.
75 Additionally, the <ulink
76 url="http://php.net/manual/book.simplexml.php">SimpleXML</ulink>
77 <acronym>PHP</acronym> extension is used to check if a returned
78 <constant>NULL</constant> value from <methodname>wddx_unserialize()</methodname> is
79 based on a serialized <constant>NULL</constant> or on invalid data.
83 Available options include:
86 <table id="zend.serializer.adapter.wddx.table.options">
87 <title>Zend_Serializer_Adapter_Wddx Options</title>
93 <entry>Data Type</entry>
94 <entry>Default Value</entry>
95 <entry>Description</entry>
101 <entry><emphasis>comment</emphasis></entry>
102 <entry><type>string</type></entry>
104 <entry>An optional comment that appears in the packet header.</entry>
111 <sect2 id="zend.serializer.adapter.json">
112 <title>Zend_Serializer_Adapter_Json</title>
115 The <acronym>JSON</acronym> adapter provides a bridge to the
116 <classname>Zend_Json</classname> component and/or ext/json. Please read the <link
117 linkend= "zend.json.introduction">Zend_Json documentation</link> for further
122 Available options include:
125 <table id="zend.serializer.adapter.json.table.options">
126 <title>Zend_Serializer_Adapter_Json Options</title>
131 <entry>Option</entry>
132 <entry>Data Type</entry>
133 <entry>Default Value</entry>
134 <entry>Description</entry>
140 <entry><emphasis>cycleCheck</emphasis></entry>
141 <entry><type>boolean</type></entry>
143 <entry>See <xref linkend="zend.json.advanced.objects1"/></entry>
147 <entry><emphasis>objectDecodeType</emphasis></entry>
148 <entry><type>Zend_Json::TYPE_*</type></entry>
149 <entry>Zend_Json::TYPE_ARRAY</entry>
150 <entry>See <xref linkend= "zend.json.advanced.objects1"/></entry>
154 <entry><emphasis>enableJsonExprFinder</emphasis></entry>
155 <entry><type>boolean</type></entry>
157 <entry>See <xref linkend= "zend.json.advanced.expr"/></entry>
164 <sect2 id="zend.serializer.adapter.amf03">
165 <title>Zend_Serializer_Adapter_Amf 0 and 3</title>
168 The <acronym>AMF</acronym> adapters, <classname>Zend_Serializer_Adapter_Amf0</classname>
169 and <classname>Zend_Serializer_Adapter_Amf3</classname>, provide a bridge to the
170 serializer of the <classname>Zend_Amf</classname> component. Please read the <link
171 linkend= "zend.amf.introduction">Zend_Amf documentation</link> for further
176 There are no options for these adapters.
180 <sect2 id="zend.serializer.adapter.pythonpickle">
181 <title>Zend_Serializer_Adapter_PythonPickle</title>
184 This adapter converts <acronym>PHP</acronym> types to a <ulink
185 url="http://docs.python.org/library/pickle.html">Python Pickle</ulink> string
186 representation. With it, you can read the serialized data with Python and read Pickled
187 data of Python with <acronym>PHP</acronym>.
191 Available options include:
194 <table id="zend.serializer.adapter.pythonpickle.table.options">
195 <title>Zend_Serializer_Adapter_PythonPickle Options</title>
200 <entry>Option</entry>
201 <entry>Data Type</entry>
202 <entry>Default Value</entry>
203 <entry>Description</entry>
209 <entry><emphasis>protocol</emphasis></entry>
210 <entry><type>integer</type> (0 | 1 | 2 | 3)</entry>
214 The Pickle protocol version used on
215 <methodname>serialize</methodname>
223 Datatype merging (PHP to Python) occurs as follows:
226 <table id="zend.serializer.adapter.pythonpickle.table.php2python">
227 <title>Datatype merging (PHP to Python)</title>
232 <entry>PHP Type</entry>
233 <entry>Python Type</entry>
239 <entry><type>NULL</type></entry>
240 <entry><type>None</type></entry>
244 <entry><type>boolean</type></entry>
245 <entry><type>boolean</type></entry>
249 <entry><type>integer</type></entry>
250 <entry><type>integer</type></entry>
254 <entry><type>float</type></entry>
255 <entry><type>float</type></entry>
259 <entry><type>string</type></entry>
260 <entry><type>string</type></entry>
264 <entry><type>array</type></entry>
265 <entry><type>list</type></entry>
269 <entry><type>associative array</type></entry>
270 <entry><type>dictionary</type></entry>
274 <entry><type>object</type></entry>
275 <entry><type>dictionary</type></entry>
282 Datatype merging (Python to <acronym>PHP</acronym>) occurs per the following:
285 <table id="zend.serializer.adapter.pythonpickle.table.python2php">
286 <title>Datatype merging (Python to PHP)</title>
291 <entry>Python-Type</entry>
292 <entry>PHP-Type</entry>
298 <entry><type>None</type></entry>
299 <entry><type>NULL</type></entry>
303 <entry><type>boolean</type></entry>
304 <entry><type>boolean</type></entry>
308 <entry><type>integer</type></entry>
309 <entry><type>integer</type></entry>
313 <entry><type>long</type></entry>
316 <type>integer</type> | <type>float</type> | <type>string</type>
317 | <classname>Zend_Serializer_Exception</classname>
322 <entry><type>float</type></entry>
323 <entry><type>float</type></entry>
327 <entry><type>string</type></entry>
328 <entry><type>string</type></entry>
332 <entry><type>bytes</type></entry>
333 <entry><type>string</type></entry>
337 <entry><type>Unicode string</type></entry>
338 <entry><type>UTF-8 string</type></entry>
342 <entry><type>list</type></entry>
343 <entry><type>array</type></entry>
347 <entry><type>tuple</type></entry>
348 <entry><type>array</type></entry>
352 <entry><type>dictionary</type></entry>
353 <entry><type>associative array</type></entry>
357 <entry>All other types</entry>
358 <entry><classname>Zend_Serializer_Exception</classname></entry>
365 <sect2 id="zend.serializer.adapter.phpcode">
366 <title>Zend_Serializer_Adapter_PhpCode</title>
369 This adapter generates a parsable <acronym>PHP</acronym> code representation using
370 <ulink url="http://php.net/manual/function.var-export.php">var_export()</ulink>. On
371 restoring, the data will be executed using <ulink
372 url="http://php.net/manual/function.eval.php">eval</ulink>.
376 There are no configuration options for this adapter.
380 <title>Unserializing objects</title>
383 Objects will be serialized using the <ulink
384 url="http://php.net/manual/language.oop5.magic.php#language.oop5.magic.set-state">__set_state</ulink>
385 magic method. If the class doesn't implement this method, a fatal error will occur
391 <title>Uses eval()</title>
394 The <classname>PhpCode</classname> adapter utilizes <methodname>eval()</methodname>
395 to unserialize. This introduces both a performance and potential security issue as a
396 new process will be executed. Typically, you should use the
397 <methodname>PhpSerialize</methodname> adapter unless you require human-readability
398 of the serialized data.