大网数据广告活动
PHP 语言与运行手册

MongoDB\BSON\Persistable::bsonSerialize · Provides an array or document to serialize as BSON

· 52CE 我爱测

MongoDB\BSON\Persistable::bsonSerialize — Provides an array or document to serialize as BSON

MongoDB\BSON\Persistable::bsonSerialize

(mongodb >=1.0.0)

MongoDB\BSON\Persistable::bsonSerialize — Provides an array or document to serialize as BSON

说明

abstract public function MongoDB\BSON\Persistable::bsonSerialize(): array|stdClass|MongoDB\BSON\Document

Called during serialization of the object to BSON. The method must return an array, stdClass, or MongoDB\BSON\Document.

The return value will always be serialized as a BSON document. The serialized document will include a field containing the class name of the object. For this reason, it is not possible to return a MongoDB\BSON\PackedArray instance in this method.

Users are encouraged to include an _id property (e.g. a MongoDB\BSON\ObjectId initialized in the constructor) when returning data for a BSON root document. In the absence of an _id property, the extension or server will generate a MongoDB\BSON\ObjectId for insert or upsert operations, respectively.

参数

此函数没有参数。

返回值

An array, stdClass, or MongoDB\BSON\Document to be serialized as a BSON document.

更新日志

版本 说明
PECL mongodb 2.0.0 之前声明为暂定的返回类型现在已被强制执行。
PECL mongodb 1.17.0 This method may now also return MongoDB\BSON\Document instances in addition to array and stdClass.

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。