php-doc-en/reference/mongo/mongoid/construct.xml

151 lines
3.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongoid.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoId::__construct</refname>
<refpurpose>Creates a new id</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <methodname>MongoId::__construct</methodname>
<methodparam choice="opt"><type>string|MongoId</type><parameter>id</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>id</parameter>
</term>
<listitem>
<para>
A string (must be 24 hexadecimal characters) or a
<classname>MongoId</classname> instance.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a new id.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>1.4.0</entry>
<entry>
An exception is thrown when passed invalid string
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoId::__construct</function> example</title>
<para>
This example shows how to create a new id. This is seldom necessary, as the
driver adds an id to arrays automatically before storing them in the
database.
</para>
<programlisting role="php">
<![CDATA[
<?php
$id1 = new MongoId();
echo "$id1\n";
$id2 = new MongoId();
echo "$id2\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
49a7011a05c677b9a916612a
49a702d5450046d3d515d10d
]]>
</screen>
</example>
<example>
<title>Parameter example</title>
<para>This example shows how to use a string parameter to initialize a MongoId with a given value.</para>
<programlisting role="php">
<![CDATA[
<?php
$id1 = new MongoId();
// create a new id from $id1
$id2 = new MongoId("$id1");
// show that $id1 and $id2 have the same hexidecimal value
var_dump($id1 == $id2);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
bool(true)
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>MongoId::__toString</methodname></member>
<member><methodname>MongoId::isvalid</methodname></member>
</simplelist>
</para>
</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
-->