php8.5
Home/ Manual/ bson / objectid/ MongoDB\BSON\ObjectId::__toString

MongoDB\BSON\ObjectId::__toString

PHP function Edit on GitHub ✎

(mongodb >=1.0.0)

Returns the hexadecimal representation of this ObjectId

Description

MongoDB\BSON\ObjectId::__toString(): string

Parameters Parameters

Return Values

Returns the hexadecimal representation of this ObjectId.

Examples

MongoDB\BSON\ObjectId::__toString() example

php
<?php

var_dump((string) new MongoDB\BSON\ObjectId());
var_dump((string) new MongoDB\BSON\ObjectId('000000000000000000000001'));

?>

The above example will output something similar to:

output
string(24) "56731b49da14d8747d701211"
string(24) "000000000000000000000001"

See Also

  • ObjectId Reference
  • BSON Types: ObjectId

Source: reference/mongodb/bson/objectid/tostring.xml · from the official PHP manual (php/doc-en)