--TEST-- MongoDB\BSON\Regex::jsonSerialize() with json_encode() (without flags) --FILE-- new MongoDB\BSON\Regex('pattern')]; $json = json_encode($doc); echo toJSON(fromPHP($doc)), "\n"; echo $json, "\n"; var_dump(toPHP(fromJSON($json))); ?> ===DONE=== --EXPECTF-- { "foo" : { "$regex" : "pattern", "$options" : "" } } {"foo":{"$regex":"pattern","$options":""}} object(stdClass)#%d (%d) { ["foo"]=> object(MongoDB\BSON\Regex)#%d (%d) { ["pattern"]=> string(7) "pattern" ["flags"]=> string(0) "" } } ===DONE===