MongoId::__construct
(PECL mongo >= 0.8.0)
MongoId::__construct — Creates a new id
このメソッドを定義している拡張モジュールは非推奨です。
かわりに MongoDB 拡張モジュールを使うべきです。 このメソッドの代替として、以下が使えます。
説明
public MongoId::__construct
([ string|MongoId $id
= null
] )
返り値
Returns a new id.
変更履歴
バージョン | 説明 |
---|---|
PECL mongo 1.4.0 | An exception is thrown when passed invalid string |
例
例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"; ?>
上の例の出力は、 たとえば以下のようになります。
49a7011a05c677b9a916612a 49a702d5450046d3d515d10d
例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); ?>
上の例の出力は、 たとえば以下のようになります。
bool(true)
参考
- MongoId::__toString() - Returns a hexidecimal representation of this id
- MongoId::isvalid() - Check if a value is a valid ObjectId