PHP » GoLang |
login |
register |
about
|
GoLang MongoDB\BSON\Serializable::bsonSerialize
request it (370)
GoLang replacement for PHP's MongoDB\BSON\Serializable::bsonSerialize
[edit | history]
PHP MongoDB\BSON\Serializable::bsonSerializePHP original manual for MongoDB\BSON\Serializable::bsonSerialize [ show | php.net ]MongoDB\BSON\Serializable::bsonSerialize(mongodb >=1.0.0) MongoDB\BSON\Serializable::bsonSerialize — Provides an array or document to serialize as BSON Description
abstract public array|object MongoDB\BSON\Serializable::bsonSerialize
( void
)
Called during serialization of the object to BSON. The method must return an array or stdClass. Root documents (e.g. a MongoDB\BSON\Serializable passed to MongoDB\BSON\fromPHP()) will always be serialized as a BSON document. For field values, associative arrays and stdClass instances will be serialized as a BSON document and sequential arrays (i.e. sequential, numeric indexes starting at 0) will be serialized as a BSON array. Users are encouraged to include an _id property (e.g. a MongoDB\BSON\ObjectId initialized in your constructor) when returning data for a BSON root document; otherwise, the driver or database will need to generate a MongoDB\BSON\ObjectId when inserting or upserting the document, respectively. ParametersThis function has no parameters. Return ValuesAn array or stdClass to be serialized as a BSON array or document. ExamplesExample #1 MongoDB\BSON\Serializable::bsonSerialize() returning an associative array for root document
<?php The above example will output something similar to: { "_id" : { "$oid" : "56cccdcada14d8755a58c591" }, "foo" : "bar" } Example #2 MongoDB\BSON\Serializable::bsonSerialize() returning a sequential array for root document
<?php The above example will output: { "0" : 1, "1" : 2, "2" : 3 } Example #3 MongoDB\BSON\Serializable::bsonSerialize() returning an associative array for document field
<?php The above example will output: { "document" : { "foo" : "bar" } } Example #4 MongoDB\BSON\Serializable::bsonSerialize() returning a sequential array for document field
<?php The above example will output: { "array" : [ 1, 2, 3 ] } See Also
|
more
Recently updated
more
Most requested
more
Last requests
|