MongoDB\BSON\ObjectId::__construct

(mongodb >=1.0.0)

MongoDB\BSON\ObjectId::__constructConstruct a new ObjectId

说明

final public MongoDB\BSON\ObjectId::__construct ( string $id = ? )

参数

id (string)

A 24-character hexadecimal string. If not provided, the driver will generate an ObjectId.

错误/异常

范例

Example #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"
}

User Contributed Notes

fejlesztes at letscode dot hu 22-Jan-2016 01:35
If you pass NULL to the __construct() method, it wont throw exceptions, nor errors, but prematurely ends the PHP processing (so it produced an 502 response over nginx), not like the legacy MongoId class.
PHP8中文手册 站长在线 整理 版权归PHP文档组所有