PHP 8.4.1 Released!

MongoDB\BSON\ObjectId::__construct

(mongodb >=1.0.0)

MongoDB\BSON\ObjectId::__constructConstruct a new ObjectId

Опис

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

Параметри

id (string)

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

Помилки/виключення

Приклади

Приклад #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"
}

Прогляньте також

add a note

User Contributed Notes 1 note

up
4
fejlesztes at letscode dot hu
8 years ago
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.
To Top