php8.5
Home/ Manual/ mongodb / bson/ The MongoDB\BSON\Persistable interface

The MongoDB\BSON\Persistable interface

Classes may implement this interface to take advantage of automatic ODM (object document mapping) behavior in the extension. During serialization, the extension will inject a __pclass property containing the PHP class name into the data returned by MongoDB\BSON\Serializable::bsonSerialize. During unserialization, the same __pclass property will then be used to infer the PHP class (independent of any type map configuration) to be constructed before MongoDB\BSON\Unserializable::bsonUnserialize is invoked. See for additional information.

Intro

Classes may implement this interface to take advantage of automatic ODM (object document mapping) behavior in the extension. During serialization, the extension will inject a __pclass property containing the PHP class name into the data returned by MongoDB\BSON\Serializable::bsonSerialize(). During unserialization, the same __pclass property will then be used to infer the PHP class (independent of any type map configuration) to be constructed before MongoDB\BSON\Unserializable::bsonUnserialize() is invoked. See mongodb.persistence for additional information.

Note

Even if MongoDB\BSON\Serializable::bsonSerialize() would return a sequential array, injection of the __pclass property will cause the object to be serialized as a BSON document.

Interfacesynopsis

class MongoDB\BSON\Persistable { }

Persistable

In this section

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