uTools-Manuals/docs/php/mongodb.bson_tophp.html
2019-04-28 19:00:34 +08:00

192 lines
8.2 KiB
HTML

<!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>Returns the PHP representation of a BSON value</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><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 class="refsect1 description" id="refsect1-function.mongodb.bson-tophp-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>MongoDB\BSON\toPHP</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$bson</code></span>
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$typeMap</code><span class="initializer"> = array()</span></span>
] ) : <span class="type"><a href="language.pseudo-types.html#language.types.array-object" class="type array|object">array|object</a></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">
Fields containing deprecated BSON types (i.e. undefined, symbol,
DBPointer) are represented only by bare-bones objects of the classes
<a href="class.mongodb_bson_undefined.html" class="classname">MongoDB\BSON\Undefined</a>,
<a href="class.mongodb_bson_symbol.html" class="classname">MongoDB\BSON\Symbol</a>, and
<a href="class.mongodb_bson_dbpointer.html" class="classname">MongoDB\BSON\DBPointer</a>, when converting BSON to
PHP. These objects are created from BSON data and used for storing these
types back into the database, but can not be instantiated as they have a
private constructor.
</p>
</div>
</div>
<div class="refsect1 parameters" id="refsect1-function.mongodb.bson-tophp-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">bson</code> (<span class="type"><a href="language.types.string.html" 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.html" class="type array">array</a></span>)</dt>
<dd>
<p class="para">
<a href="mongodb.persistence.deserialization.html#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">返回值</h3>
<p class="para">
The unserialized PHP value.
</p>
</div>
<div class="refsect1 errors" id="refsect1-function.mongodb.bson-tophp-errors">
<h3 class="title">错误/异常</h3>
<ul class="simplelist">
<li class="member">
Throws
<a href="class.mongodb_driver_exception_invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a> if
a class in the type map cannot be instantiated or does not implement
<span class="interfacename"><a href="class.mongodb_bson_unserializable.html" class="interfacename">MongoDB\BSON\Unserializable</a></span>.
</li>
<li class="member">Throws <a href="class.mongodb_driver_exception_unexpectedvalueexception.html" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a> 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/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">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>1.4.0</td>
<td>
<p class="para">
If the input contains an unsupported, deprecated BSON type, the
driver 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>1.3.2</td>
<td>
<p class="para">
<a href="class.mongodb_driver_exception_unexpectedvalueexception.html" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a>
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 driver will now log a warning to the debug log
(see: <a href="mongodb.configuration.html#ini.mongodb.debug" class="link">mongodb.debug</a>).
</p>
</td>
</tr>
<tr>
<td>1.3.0</td>
<td>
<p class="para">
<a href="class.mongodb_driver_exception_unexpectedvalueexception.html" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a>
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">范例</h3>
<div class="example" id="example-1708">
<p><strong>Example #1 <span class="function"><strong>MongoDB\BSON\toPHP()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$bson&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">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>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
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">参见</h3>
<ul class="simplelist">
<li class="member"><span class="function"><a href="mongodb.bson_fromphp.html" class="function" rel="rdfs-seeAlso">MongoDB\BSON\fromPHP()</a> - Returns the BSON representation of a PHP value</span></li>
<li class="member"><a href="https://docs.mongodb.com/manual/reference/bson-types/" class="link external">&raquo;&nbsp;MongoDB BSON</a></li>
<li class="member"><a href="mongodb.persistence.html" class="xref">Persisting Data</a></li>
</ul>
</div>
</div></div></div></body></html>