PHP Portal » PHP Handbuch » MongoId::__construct

Werbung

MongoId::__construct


(PECL mongo >= 0.8.0)

MongoId::__constructCreates a new id

Beschreibung

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

Parameter-Liste

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.

Rückgabewerte

Returns a new id.

Beispiele

Beispiel #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 Code
1
2
3
4
$id1 = new MongoId(); echo "$id1\n"; $id2 = new MongoId(); echo "$id2\n";

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

49a7011a05c677b9a916612a
49a702d5450046d3d515d10d

Beispiel #2 Parameter example

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

PHP Code
1
2
3
4
5
$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);

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

bool(true)

Siehe auch