MongoDB\BSON\ObjectId::__construct
(mongodb >=1.0.0)
MongoDB\BSON\ObjectId::__construct — Construct a new ObjectId
参数
id(string)-
A 24-character hexadecimal string. If not provided, the extension will generate an ObjectId.
错误/异常
- Throws MongoDB\Driver\Exception\InvalidArgumentException on argument parsing errors.
- Throws MongoDB\Driver\Exception\InvalidArgumentException if
idis not a 24-character hexadecimal string.
示例
示例 #1 MongoDB\BSON\ObjectId::__construct() example
<?php
var_dump(new MongoDB\BSON\ObjectId());
var_dump(new MongoDB\BSON\ObjectId('000000000000000000000001'));
?>以上示例的输出类似于:
object(MongoDB\BSON\ObjectId)#1 (1) {
["oid"]=>
string(24) "56732d3dda14d81214634921"
}
object(MongoDB\BSON\ObjectId)#1 (1) {
["oid"]=>
string(24) "000000000000000000000001"
}