Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5708

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generates a storable representation of a value</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.print-r.html">print_r</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.settype.html">settype</a></div>
 <div class="up"><a href="ref.var.html">Variable handling Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.serialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">serialize</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">serialize</span> &mdash; <span class="dc-title">Generates a storable representation of a value</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.serialize-description">
  <h3 class="title">Description</h3>
   <div class="methodsynopsis dc-description">
    <span class="type">string</span> <span class="methodname"><strong>serialize</strong></span>
     ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
    )</div>

  <p class="para rdfs-comment">
   Generates a storable representation of a value.
  </p>
  <p class="para">
   This is useful for storing or passing PHP values around without
   losing their type and structure.
  </p>
  <p class="para">
   To make the serialized string into a PHP value again, use
    <span class="function"><a href="function.unserialize.html" class="function">unserialize()</a></span>.  
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.serialize-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">value</code></em></span>
     <dd>

      <p class="para">
       The value to be serialized.  <span class="function"><strong>serialize()</strong></span>
       handles all types, except the <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>-type.
       You can even  <span class="function"><strong>serialize()</strong></span> arrays that contain
       references to itself. Circular references inside the array/object you 
       are serializing will also be stored. Any other 
       reference will be lost.
      </p>
      <p class="para">
       When serializing objects, PHP will attempt to call the member function
       <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> prior to serialization. 
       This is to allow the object to do any last minute clean-up, etc. prior 
       to being serialized. Likewise, when the object is restored using 
        <span class="function"><a href="function.unserialize.html" class="function">unserialize()</a></span> the <a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> member function is called.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
       Object&#039;s private members have the class name prepended to the member
       name; protected members have a &#039;*&#039; prepended to the member name.
       These prepended values have null bytes on either side.
       </p>
      </p></blockquote>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.serialize-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a string containing a byte-stream representation of 
   <em><code class="parameter">value</code></em> that can be stored anywhere.
  </p>
  <p class="para">
   Note that this is a binary string which may include null bytes, and needs
   to be stored and handled as such. For example,
    <span class="function"><strong>serialize()</strong></span> output should generally be stored in a BLOB
   field in a database, rather than a CHAR or TEXT field.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.serialize-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-5271">
    <p><strong>Example #1  <span class="function"><strong>serialize()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$session_data&nbsp;contains&nbsp;a&nbsp;multi-dimensional&nbsp;array&nbsp;with&nbsp;session<br />//&nbsp;information&nbsp;for&nbsp;the&nbsp;current&nbsp;user.&nbsp;&nbsp;We&nbsp;use&nbsp;serialize()&nbsp;to&nbsp;store<br />//&nbsp;it&nbsp;in&nbsp;a&nbsp;database&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;request.<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"webdb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"php"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"chicken"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"UPDATE&nbsp;sessions&nbsp;SET&nbsp;data&nbsp;=&nbsp;?&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sqldata&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(</span><span style="color: #0000BB">serialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$session_data</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'PHP_AUTH_USER'</span><span style="color: #007700">]);<br />if&nbsp;(!</span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sqldata</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;sessions&nbsp;(id,&nbsp;data)&nbsp;VALUES(?,&nbsp;?)"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sqldata</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Something&nbsp;went&nbsp;wrong..&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.serialize-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.0.7</td>
       <td>
        The object serialization process was fixed.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.serialize-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Note that many built-in PHP objects cannot be serialized. However, those with 
    this ability either implement the <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> interface or the 
    magic <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> and
    <a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> methods. If an 
    internal class does not fulfill any of those requirements, it cannot reliably be 
    serialized.
   </p>
   <p class="para">
    There are some historical exceptions to the above rule, where some internal objects 
    could be serialized without implementing the interface or exposing the methods. Notably, 
    the <a href="class.arrayobject.html" class="classname">ArrayObject</a> prior to PHP 5.2.0.
   </p>
  </p></blockquote>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    When  <span class="function"><strong>serialize()</strong></span> serializes objects, the leading slash is not included in the class name of namespaced classes for maximum compatibility.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.serialize-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.unserialize.html" class="function" rel="rdfs-seeAlso">unserialize()</a> - Creates a PHP value from a stored representation</span></li>
    <li class="member"> <span class="function"><a href="function.var-export.html" class="function" rel="rdfs-seeAlso">var_export()</a> - Outputs or returns a parsable string representation of a variable</span></li>
    <li class="member"> <span class="function"><a href="function.json-encode.html" class="function" rel="rdfs-seeAlso">json_encode()</a> - Returns the JSON representation of a value</span></li>
    <li class="member"><a href="language.oop5.serialization.html" class="link">Serializing Objects</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.print-r.html">print_r</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.settype.html">settype</a></div>
 <div class="up"><a href="ref.var.html">Variable handling Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>