php-doc-en/reference/mongodb/functions/bson/tophp.xml
2015-11-10 21:15:10 +00:00

122 lines
3.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 336263 $ -->
<refentry xml:id="function.mongodb.bson-tophp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoDB\BSON\toPHP</refname>
<refpurpose>Returns the PHP representation of a BSON value</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array|object</type><methodname>MongoDB\BSON\toPHP</methodname>
<methodparam><type>string</type><parameter>bson</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>typeMap</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
<para>
Unserializes a BSON document (i.e. binary string) to its PHP representation.
The <parameter>typeMap</parameter> paramater may be used to control the PHP
types used for converting BSON arrays and documents (both root and embedded).
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>bson</parameter> (<type>string</type>)</term>
<listitem>
<para>
BSON value to be unserialized.
</para>
</listitem>
</varlistentry>
&mongodb.parameter.typeMap;
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The unserialized PHP value.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws
<classname>MongoDB\Driver\Exception\InvalidArgumentException</classname> if
a class in the type map cannot be instantiated or does not implement
<classname>MongoDB\BSON\Unserializable</classname>.
</para>
<para>
Throws
<classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> 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
<link xlink:href="&url.mongodb.libbson;">libbson</link> error.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoDB\BSON\toPHP</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$bson = hex2bin('0e00000010666f6f000100000000');
$value = MongoDB\BSON\toPHP($bson);
var_dump($value);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(stdClass)#1 (1) {
["foo"]=>
int(1)
}
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>MongoDB\BSON\fromPHP</function></member>
<member><link xlink:href="&url.mongodb.docs.bson;">MongoDB BSON</link></member>
<member><xref linkend="mongodb.persistence"/></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->