<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.bson.functions.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.mongodb.bson-tophp.php',
    1 => 'MongoDB\\BSON\\toPHP',
    2 => 'Returns the PHP representation of a BSON value',
  ),
  'up' => 
  array (
    0 => 'ref.bson.functions.php',
    1 => 'Functions',
  ),
  'prev' => 
  array (
    0 => 'function.mongodb.bson-tojson.php',
    1 => 'MongoDB\\BSON\\toJSON',
  ),
  'next' => 
  array (
    0 => 'function.mongodb.bson-torelaxedextendedjson.php',
    1 => 'MongoDB\\BSON\\toRelaxedExtendedJSON',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/functions/bson/tophp.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mongodb.bson-tophp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\toPHP</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\toPHP</span> &mdash; <span class="dc-title">Returns the PHP representation of a BSON value</span></p>

 </div>

 <div id="function.mongodb.bson-tophp-refsynopsisdiv">
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    This function has been <em>DEPRECATED</em> as of extension
    version 1.20.0 and was removed in 2.0. Applications should use
    <span class="methodname"><a href="mongodb-bson-document.tophp.php" class="methodname">MongoDB\BSON\Document::toPHP()</a></span> instead.
   </p>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mongodb.bson-tophp-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>MongoDB\BSON\toPHP</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$bson</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$typeMap</code><span class="initializer"> = array()</span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.object.php" class="type object">object</a></span></span></div>

  <p class="para rdfs-comment">
   Unserializes a BSON document (i.e. binary string) to its PHP representation.
   The <code class="parameter">typeMap</code> paramater may be used to control the PHP
   types used for converting BSON arrays and documents (both root and embedded).
  </p>
  
   <div class="warning"><strong class="warning">Warning</strong>
    <p class="simpara">
     BSON documents can technically contain duplicate keys because documents are
     stored as a list of key-value pairs; however, applications should refrain
     from generating documents with duplicate keys as server and driver behavior
     may be undefined. Since PHP objects and arrays cannot have duplicate keys,
     data could also be lost when decoding a BSON document with duplicate keys.
    </p>
   </div>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.mongodb.bson-tophp-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">bson</code> (<span class="type"><a href="language.types.string.php" class="type string">string</a></span>)</dt>
    <dd>
     <p class="para">
      BSON value to be unserialized.
     </p>
    </dd>
   
   
   
    <dt><code class="parameter">typeMap</code> (<span class="type"><a href="language.types.array.php" class="type array">array</a></span>)</dt>
    <dd>
     <p class="para">
      <a href="mongodb.persistence.php#mongodb.persistence.typemaps" class="link">Type map configuration</a>.
     </p>
    </dd>
   

  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mongodb.bson-tophp-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The unserialized PHP value.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mongodb.bson-tophp-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <ul class="simplelist">
   <li>
    Throws
    <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if
    a class in the type map cannot be instantiated or does not implement
    <span class="interfacename"><a href="class.mongodb-bson-unserializable.php" class="interfacename">MongoDB\BSON\Unserializable</a></span>.
   </li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.php" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span> if the input did not contain exactly one BSON document. Possible reasons include, but are not limited to, invalid BSON, extra data (after reading one BSON document), or an unexpected <a href="https://github.com/mongodb/mongo-c-driver/tree/master/src/libbson" class="link external">&raquo;&nbsp;libbson</a> error.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mongodb.bson-tophp-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>
         This function was removed.
        </td>
       </tr>


      <tr>
       <td>PECL mongodb 1.4.0</td>
       <td>
        <p class="para">
         If the input contains an unsupported, deprecated BSON type, the
         extension will now no longer log a warning to the debug log, but instead
         will create an object representing this type.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.3.2</td>
       <td>
        <p class="para">
         <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.php" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span>
         is no longer thrown if the input contains an unsupported, deprecated
         BSON type. Such types will be ignored (as they were in versions before
         1.3.0), although the extension will now log a warning to the debug log
         (see: <a href="mongodb.configuration.php#ini.mongodb.debug" class="link">mongodb.debug</a>).
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.3.0</td>
       <td>
        <p class="para">
         <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.php" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span>
         is thrown if the input contains an unsupported, deprecated BSON type.
         Previously, such types were ignored.
        </p>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mongodb.bson-tophp-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>MongoDB\BSON\toPHP()</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 />$bson </span><span style="color: #007700">= </span><span style="color: #0000BB">hex2bin</span><span style="color: #007700">(</span><span style="color: #DD0000">'0e00000010666f6f000100000000'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$value </span><span style="color: #007700">= </span><span style="color: #0000BB">MongoDB\BSON\toPHP</span><span style="color: #007700">(</span><span style="color: #0000BB">$bson</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</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(stdClass)#1 (1) {
  [&quot;foo&quot;]=&gt;
  int(1)
}</pre>
</div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.mongodb.bson-tophp-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="mongodb-bson-document.tophp.php" class="methodname" rel="rdfs-seeAlso">MongoDB\BSON\Document::toPHP()</a> - Returns the PHP representation of the BSON document</span></li>
   <li><span class="function"><a href="function.mongodb.bson-fromphp.php" class="function" rel="rdfs-seeAlso">MongoDB\BSON\fromPHP()</a> - Returns the BSON representation of a PHP value</span></li>
   <li><a href="https://www.mongodb.com/docs/manual/reference/bson-types/" class="link external">&raquo;&nbsp;MongoDB BSON</a></li>
   <li><a href="mongodb.persistence.php" class="xref">Persisting Data</a></li>
  </ul>
 </div>


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