PHP-1272 et al: Add missing bson_encode() tests and fix segfaults

 * https://jira.mongodb.org/browse/PHP-1272
 * https://jira.mongodb.org/browse/PHP-1273
 * https://jira.mongodb.org/browse/PHP-1277