<?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 336263 $ --> <refentry xml:id="function.mongodb.bson-fromphp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>MongoDB\BSON\fromPHP</refname> <refpurpose>Returns the BSON representation of a PHP value</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <type>string</type><methodname>MongoDB\BSON\fromPHP</methodname> <methodparam><type>array|object</type><parameter>value</parameter></methodparam> </methodsynopsis> <para> Serializes a PHP array or object (e.g. document) to its <link xlink:href="&url.mongodb.docs.bson;">BSON</link> representation. The returned binary string will describe a BSON document. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <variablelist> <varlistentry> <term><parameter>value</parameter> (<type>array|object</type>)</term> <listitem> <para> PHP value to be serialized. </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> The serialized BSON document as a binary string. </para> </refsect1> <refsect1 role="errors"> &reftitle.errors; <para> Throws <classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> if the PHP value cannot be converted to BSON. Possible reasons include, but are not limited to, encountering an unexpected <classname>MongoDB\BSON\Type</classname> instance or <function>MongoDB\BSON\Serializable::bsonSerialize</function> failing to return an <type>array</type> or <classname>stdClass</classname>. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example> <title><function>MongoDB\BSON\fromPHP</function> example</title> <programlisting role="php"> <![CDATA[ <?php $bson = MongoDB\BSON\fromPHP(['foo' => 1]); echo bin2hex($bson), "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ 0e00000010666f6f000100000000cat ]]> </screen> </example> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <simplelist> <member><function>MongoDB\BSON\toPHP</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 -->