10gen-labs/mongo-hhvm-driver — pull request #57 by lukerattei (2014-06-13 06:18:37+00:00)
Title: Fix undefined MongoClient in HHVM 3.1 and Ubuntu

This is a fix for issue #55. I haven't done any HHVM extension development until now, so I'm sorry if any of this departs from convention or doesn't make sense.

On Ubuntu and HHVM 3.1, the mongo extension would be loaded (according to `get_loaded_extensions()`) but `var_dump(new MongoClient())` would cause an exception because the class was not defined. Here are the changes I made to fix this:

- Renamed the generated `mongo.php` file to `ext_mongo.php` for consistency with other extensions and because of [this answer on SO](http://stackoverflow.com/questions/23868172/cant-load-hhvm-extension-dynamic#answer-23878380)
- Used `MONGO_DEFINE_CLASS` macro for `MongoClient`, `MongoCursor`, and `MongoCollection` (not sure if this was necessary, but the Imagick extension does this)
- Capitalized `mongoExtension` class (so now it's `MongoExtension`)
- Moved some implementation from `ext_mongo.h` to `ext_mongo.cpp`

After this change, I see the expected result in `./interactive_mode.sh`:

hphpd> var_dump(new MongoClient());
object(MongoClient)#1 (3) {
["read_preference":"MongoClient":private]=>
array(0) {
}
["databases":"MongoClient":private]=>
array(0) {
}
["__mongoc_client"]=>
resource(4) of type (mongoc client)
}