MongoDB\BSON\ObjectId::__construct
PHP function
Edit on GitHub ✎
(mongodb >=1.0.0)
Construct a new ObjectId
Description
MongoDB\BSON\ObjectId::__construct(string|null $id = null)
Parameters
id(string)A 24-character hexadecimal string. If not provided, the extension will generate an ObjectId.
Errors/Exceptions
- Throws
MongoDB\Driver\Exception\InvalidArgumentExceptionifidis not a 24-character hexadecimal string.
Examples
MongoDB\BSON\ObjectId::__construct() example
php
<?php
var_dump(new MongoDB\BSON\ObjectId());
var_dump(new MongoDB\BSON\ObjectId('000000000000000000000001'));
?>The above example will output something similar to:
output
object(MongoDB\BSON\ObjectId)#1 (1) {
["oid"]=>
string(24) "56732d3dda14d81214634921"
}
object(MongoDB\BSON\ObjectId)#1 (1) {
["oid"]=>
string(24) "000000000000000000000001"
}See Also
- ObjectId Reference
- BSON Types: ObjectId