downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoId::__toString> <MongoId
Last updated: Fri, 20 Nov 2009

view this page in

MongoId::__construct

(PECL mongo >= 0.8.0)

MongoId::__constructCreates a new id

Description

MongoId::__construct ([ string $id = NULL ] )

Parameters

id

A string to use as the id. Must be 24 hexidecimal characters. If an invalid string is passed to this constructor, the constructor will ignore it and create a new id value.

Return Values

Returns a new id.

Examples

Example #1 MongoId::__construct() example

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.

<?php

  $id1 
= new MongoId();
  echo 
"$id1\n";

  
$id2 = new MongoId();
  echo 
"$id2\n";

  
?>

The above example will output something similar to:

49a7011a05c677b9a916612a
49a702d5450046d3d515d10d

Example #2 Parameter example

This example shows how to use a string parameter to initialize a MongoId with a given value.

<?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);
  
?>

The above example will output something similar to:

bool(true)

See Also



add a note add a note User Contributed Notes
MongoId::__construct
There are no user contributed notes for this page.

MongoId::__toString> <MongoId
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites