<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mongodb-bson-unserializable.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'mongodb-bson-unserializable.bsonunserialize.php',
    1 => 'MongoDB\\BSON\\Unserializable::bsonUnserialize',
    2 => 'Constructs the object from a BSON array or document',
  ),
  'up' => 
  array (
    0 => 'class.mongodb-bson-unserializable.php',
    1 => 'MongoDB\\BSON\\Unserializable',
  ),
  'prev' => 
  array (
    0 => 'class.mongodb-bson-unserializable.php',
    1 => 'MongoDB\\BSON\\Unserializable',
  ),
  'next' => 
  array (
    0 => 'class.mongodb-bson-binaryinterface.php',
    1 => 'MongoDB\\BSON\\BinaryInterface',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/bson/unserializable/bsonunserialize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mongodb-bson-unserializable.bsonunserialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\Unserializable::bsonUnserialize</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\Unserializable::bsonUnserialize</span> &mdash; <span class="dc-title">Constructs the object from a BSON array or document</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-bson-unserializable.bsonunserialize-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\BSON\Unserializable::bsonUnserialize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   Called during unserialization of the object from BSON. The properties of the
   BSON array or document will be passed to the method as an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
  </p>
  <p class="para">
   Remember to check for an <span class="property">_id</span> property when handling data
   from a BSON document.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    This method acts as the
    <a href="language.oop5.decon.php#language.oop5.decon.constructor" class="link">constructor</a> of the
    object. The <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a> method
    will <em>not</em> be called after this method.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-bson-unserializable.bsonunserialize-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">data</code> (<span class="type"><a href="language.types.array.php" class="type array">array</a></span>)</dt>
    <dd>
     <p class="para">
      Properties within the BSON array or document.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-bson-unserializable.bsonunserialize-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The return value from this method is ignored.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-bson-unserializable.bsonunserialize-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>PECL mongodb 2.0.0</td>
        <td>
         Return types previously declared as tentative are now enforced.
        </td>
       </tr>


     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodb-bson-unserializable.bsonunserialize-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>MongoDB\BSON\Unserializable::bsonUnserialize()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">MyDocument </span><span style="color: #007700">implements </span><span style="color: #0000BB">MongoDB\BSON\Unserializable<br /></span><span style="color: #007700">{<br />    private </span><span style="color: #0000BB">$data </span><span style="color: #007700">= [];<br /><br />    function </span><span style="color: #0000BB">bsonUnserialize</span><span style="color: #007700">(array </span><span style="color: #0000BB">$data</span><span style="color: #007700">): </span><span style="color: #0000BB">void<br />    </span><span style="color: #007700">{<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">data </span><span style="color: #007700">= </span><span style="color: #0000BB">$data</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$bson </span><span style="color: #007700">= </span><span style="color: #0000BB">MongoDB\BSON\Document</span><span style="color: #007700">::</span><span style="color: #0000BB">fromJSON</span><span style="color: #007700">(</span><span style="color: #DD0000">'{ "foo": "bar" }'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$bson</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">toPHP</span><span style="color: #007700">([</span><span style="color: #DD0000">'root' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'MyDocument'</span><span style="color: #007700">]));<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(MyDocument)#1 (1) {
  [&quot;data&quot;:&quot;MyDocument&quot;:private]=&gt;
  array(1) {
    [&quot;foo&quot;]=&gt;
    string(3) &quot;bar&quot;
  }
}</pre>
</div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-bson-unserializable.bsonunserialize-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="mongodb-bson-serializable.bsonserialize.php" class="function" rel="rdfs-seeAlso">MongoDB\BSON\Serializable::bsonSerialize()</a> - Provides an array or document to serialize as BSON</span></li>
   <li><span class="interfacename"><a href="class.mongodb-bson-persistable.php" class="interfacename">MongoDB\BSON\Persistable</a></span></li>
   <li><a href="mongodb.persistence.php" class="xref">Persisting Data</a></li>
  </ul>
 </div>


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