--TEST-- MongoDB\BSON\Document::fromPHP(): Encodes Persistable objects as a document --FILE-- $this->foo, 'bar' => $this->bar, 'baz' => $this->baz, ]; } public function bsonUnserialize(array $data): void { // Unused } } $bson = MongoDB\BSON\Document::fromPHP(new MyDocument); echo $bson->toRelaxedExtendedJSON(), "\n"; ?> ===DONE=== --EXPECT-- { "__pclass" : { "$binary" : { "base64" : "TXlEb2N1bWVudA==", "subType" : "80" } }, "foo" : 1, "bar" : 2, "baz" : 3 } ===DONE===