函数名称:MongoDB\BSON\Document::__toString()
适用版本:PHP 5 >= 5.6.0, PHP 7, PHP 8
函数描述:该函数用于将MongoDB\BSON\Document对象转换为字符串表示形式。
用法:
public MongoDB\BSON\Document::__toString(): string
示例:
// 创建一个MongoDB\BSON\Document对象
$document = new MongoDB\BSON\Document([
'name' => 'John Doe',
'age' => 25,
'email' => 'johndoe@example.com'
]);
// 调用__toString()方法将Document对象转换为字符串
echo $document->__toString();
输出:
{"name":"John Doe","age":25,"email":"johndoe@example.com"}
注意事项: