--TEST-- Enums implementing Serializable round-tripped through parent document --SKIPIF-- --FILE-- $this->x, 'y' => $this->y, ]; } public function bsonUnserialize(array $data): void { if (isset($data['x'])) { // See: https://www.php.net/manual/en/language.enumerations.basics.php#127112 $this->x = constant(MyEnum::class . '::' . $data['x']->name); } if (isset($data['y'])) { $this->y = MyBackedEnum::from($data['y']->value); } } } $document = new MyDocument(MyEnum::A, MyBackedEnum::A); var_dump(toPHP(fromPHP($document))); ?> ===DONE=== --EXPECTF-- object(MyDocument)#%d (%d) { ["x":"MyDocument":private]=> enum(MyEnum::A) ["y":"MyDocument":private]=> enum(MyBackedEnum::A) } ===DONE===