<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.igbinary.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.igbinary-serialize.php',
    1 => 'igbinary_serialize',
    2 => 'Generates a compact, storable binary representation of a value',
  ),
  'up' => 
  array (
    0 => 'ref.igbinary.php',
    1 => 'Igbinary 函数',
  ),
  'prev' => 
  array (
    0 => 'ref.igbinary.php',
    1 => 'Igbinary 函数',
  ),
  'next' => 
  array (
    0 => 'function.igbinary-unserialize.php',
    1 => 'igbinary_unserialize',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/igbinary/functions/igbinary-serialize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.igbinary-serialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">igbinary_serialize</h1>
  <p class="verinfo">(PECL igbinary &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">igbinary_serialize</span> &mdash; <span class="dc-title">Generates a compact, storable binary representation of a value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.igbinary-serialize-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>igbinary_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"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   Generates a storable representation of a value.
  </p>
  <p class="simpara">
   This is useful for storing or passing PHP values around without
   losing their type and structure.
  </p>
  <p class="simpara">
   To make the serialized string into a PHP value again,
   <span class="function"><a href="function.igbinary-unserialize.php" class="function">igbinary_unserialize()</a></span> can be used.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.igbinary-serialize-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">value</code></dt>
    <dd>
      <span class="simpara">
       The value to be serialized. <span class="function"><strong>igbinary_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).
       Even <span class="type"><a href="language.types.array.php" class="type array">array</a></span>s that contain references to itself can be processed by <span class="function"><strong>igbinary_serialize()</strong></span>.
       Circular references inside the <span class="type"><a href="language.types.array.php" class="type array">array</a></span> or <span class="type"><a href="language.types.object.php" class="type object">object</a></span> that is being serializend will also be stored.
       Any other reference will be lost.
      </span>
      <span class="simpara">
       When serializing objects, igbinary 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.igbinary-unserialize.php" class="function">igbinary_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.
      </span>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <span class="simpara">
        Private members of <span class="type"><a href="language.types.object.php" class="type object">object</a></span>s have the class name prepended to the member
        name; protected members have a <code class="literal">&#039;*&#039;</code> prepended to the member name.
        These prepended values have null bytes on either side.
       </span>
      </p></blockquote>
     </dd>
   
  </dl>
 </div>


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


 <div class="refsect1 examples" id="refsect1-function.igbinary-serialize-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 <span class="function"><strong>igbinary_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 />$ser </span><span style="color: #007700">= </span><span style="color: #0000BB">igbinary_serialize</span><span style="color: #007700">([</span><span style="color: #DD0000">'test'</span><span style="color: #007700">, </span><span style="color: #DD0000">'test'</span><span style="color: #007700">]);<br />echo </span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$ser</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">igbinary_unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$ser</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例会输出：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">%00%00%00%02%14%02%06%00%11%04test%06%01%0E%00
array (
  0 =&gt; &#039;test&#039;,
  1 =&gt; &#039;test&#039;,
)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.igbinary-serialize-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    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 with any serializer.
   </span>
   <span class="simpara">
    There are some historical exceptions to the above rule, where some internal objects
    could be serialized without implementing the interface or exposing the methods.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.igbinary-serialize-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.serialize.php" class="function" rel="rdfs-seeAlso">serialize()</a> - 生成值的可存储表示</span></li>
   <li><span class="function"><a href="function.igbinary-unserialize.php" class="function" rel="rdfs-seeAlso">igbinary_unserialize()</a> - Creates a PHP value from a stored representation from igbinary_serialize</span></li>
   <li><span class="function"><a href="function.var-export.php" class="function" rel="rdfs-seeAlso">var_export()</a> - 输出或返回变量的可解析字符串表示</span></li>
   <li><span class="function"><a href="function.json-encode.php" class="function" rel="rdfs-seeAlso">json_encode()</a> - 对变量进行 JSON 编码</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>
 </div>


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