<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.serialize.php',
    1 => 'serialize',
    2 => 'Generates a storable representation of a value',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Variable handling Функції',
  ),
  'prev' => 
  array (
    0 => 'function.print-r.php',
    1 => 'print_r',
  ),
  'next' => 
  array (
    0 => 'function.settype.php',
    1 => 'settype',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/var/functions/serialize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.serialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">serialize</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</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">Опис</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>serialize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></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.php" class="function">unserialize()</a></span>.  
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.serialize-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <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.php" class="type resource">resource</a></span>-type and some <span class="type"><a href="language.types.object.php" class="type object">object</a></span>s (see note below).
       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 functions
       <a href="language.oop5.magic.php#object.serialize" class="link">__serialize()</a> or
       <a href="language.oop5.magic.php#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.php" class="function">unserialize()</a></span> the <a href="language.oop5.magic.php#object.unserialize" class="link">__unserialize()</a> or
       <a href="language.oop5.magic.php#object.wakeup" class="link">__wakeup()</a> member function is called.
      </p>
      <blockquote class="note"><p><strong class="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>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.serialize-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns a string containing a byte-stream representation of 
   <code class="parameter">value</code> 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">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>serialize()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// $session_data contains a multi-dimensional array with session<br />// information for the current user.  We use serialize() to store<br />// it in a database at the end of the request.<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">odbc_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"webdb"</span><span style="color: #007700">, </span><span style="color: #DD0000">"php"</span><span style="color: #007700">, </span><span style="color: #DD0000">"chicken"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,<br />      </span><span style="color: #DD0000">"UPDATE sessions SET data = ? WHERE id = ?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sqldata </span><span style="color: #007700">= array (</span><span style="color: #0000BB">serialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$session_data</span><span style="color: #007700">), </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 (!</span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">$sqldata</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">odbc_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,<br />     </span><span style="color: #DD0000">"INSERT INTO sessions (id, data) VALUES(?, ?)"</span><span style="color: #007700">);<br />    if (!</span><span style="color: #0000BB">odbc_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">array_reverse</span><span style="color: #007700">(</span><span style="color: #0000BB">$sqldata</span><span style="color: #007700">))) {<br />        </span><span style="color: #FF8000">/* Something went wrong.. */<br />    </span><span style="color: #007700">}<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.serialize-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="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.php" class="interfacename">Serializable</a></span> interface or the 
    magic <a href="language.oop5.magic.php#object.serialize" class="link">__serialize()</a>/<a href="language.oop5.magic.php#object.unserialize" class="link">__unserialize()</a>
    or <a href="language.oop5.magic.php#object.sleep" class="link">__sleep()</a>/<a href="language.oop5.magic.php#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.
   </p>
  </p></blockquote>
  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    When <span class="function"><strong>serialize()</strong></span> serializes objects, the leading backslash 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">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.unserialize.php" class="function" rel="rdfs-seeAlso">unserialize()</a> - Creates a PHP value from a stored representation</span></li>
    <li><span class="function"><a href="function.var-export.php" class="function" rel="rdfs-seeAlso">var_export()</a> - Outputs or returns a parsable string representation of a variable</span></li>
    <li><span class="function"><a href="function.json-encode.php" class="function" rel="rdfs-seeAlso">json_encode()</a> - Returns the JSON representation of a value</span></li>
    <li><a href="language.oop5.serialization.php" class="link">Serializing Objects</a></li>
    <li><a href="language.oop5.magic.php#object.sleep" class="link">__sleep()</a></li>
    <li><a href="language.oop5.magic.php#object.wakeup" class="link">__wakeup()</a></li>
    <li><a href="language.oop5.magic.php#object.serialize" class="link">__serialize()</a></li>
    <li><a href="language.oop5.magic.php#object.unserialize" class="link">__unserialize()</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>