mongofill / mongofill-hhvm

A mix of the original Mongofill extension + BSON implementation in C++
MIT License
31 stars 19 forks source link

MongoConnectionException doesn't exists for hhvm #46

Open ezruneko opened 9 years ago

ezruneko commented 9 years ago

I installed on Ubuntu 14.04LTS MongoDB module in drupal:

curl http://ftp.drupal.org/files/projects/drupal-7.39.tar.gz | tar xvz
curl http://ftp.drupal.org/files/projects/mongodb-7.x-1.x-dev.tar.gz | tar xvz

# hhvm --version
HipHop VM 3.9.1 (rel)
Compiler: tags/HHVM-3.9.1-0-g0f72cfc2f0a01fdfeb72fbcfeb247b72998a66db
Repo schema: 6416960c150a4a4726fda74b659105ded8819d9c

# apt-show-versions hhvm-dev
hhvm-dev:amd64/trusty 3.9.1~trusty uptodate

And crash in line 58 in mongo.module:

\nFatal error: Class undefined: MongoConnectionException in /usr/share/nginx/closure.es/blog/sites/all/modules/mongodb/mongodb.module on line 58
//Line 58 => $mongo = new MongoClient($host, $options);

The snippet code:

    try {
      // Use the 1.3 client if available.
      if (class_exists('MongoClient')) {
        $mongo = new MongoClient($host, $options); //<-- LINE: 58
        // Enable read preference and tags if provided. This can also be
        // controlled on a per query basis at the cursor level if more control
        // is required.
        if (!empty($connection['read_preference'])) {
          $tags = !empty($connection['read_preference']['tags']) ? $connection['read_preference']['tags'] : array();
          $mongo->setReadPreference($connection['read_preference']['preference'], $tags);
        }
      }
      else {
        $mongo = new Mongo($host, $options);
        if (!empty($connection['slave_ok'])) {
          $mongo->setSlaveOkay(TRUE);
        }
      }
      $mongo_objects[$host][$db] = $mongo->selectDB($db);
      $mongo_objects[$host][$db]->connection = $mongo;
    }
    catch (MongoConnectionException $e) {
      $mongo_objects[$host][$db] = new MongoDummy();
      throw $e;
    }

But when i try a simple example like:

<?php

try {
$m = new MongoClient(); // connect
$db = $m->foo; // get the database named "foo"
}
catch (MongoConnectionException $e) {
    print_r($e);
}

?>

Any error is reported in the hhvm/error.log. Bug is generated when hhvm compile the php file because if i add a print_r($host) before $mongo = new MongoClient($host, $options); don't show my print_r()

Another test

<?php

echo 'HHVM version: ' . phpversion() . '<br/>';
echo 'MongoFill version: ' . phpversion('mongo') . '<br/>';
echo '-----------------------------------------<br/>';
echo 'MongoClient: ' . (class_exists('MongoClient') ? 'true' : 'false') . '<br/>';
echo 'MongoConnectionException: ' . (class_exists('MongoConnectionException') ? 'true' : 'false') . '<br/>';
echo 'MongoException: ' . (class_exists('MongoException') ? 'true' : 'false');

?>
//Output:
HHVM version: 5.6.99-hhvm
MongoFill version: 1.4.5
-----------------------------------------
MongoClient: true
MongoConnectionException: false
MongoException: true

Live version: http://closure.es/mongo.php


Updated:

And seems that hhvm dont find the MongoConnectionException class.

ezruneko commented 9 years ago

Solved:

I rename in MongoFill the file MongoException.php to AMongoException.php and recompile it. So the problem is the order to merge all php files in the ext_mongo.php.

MongoException must be parsed before all inherited classes.

//Test: http://closure.es/mongo.php
HHVM version: 5.6.99-hhvm
MongoFill version: 1.4.5
-----------------------------------------
MongoClient: true
MongoConnectionException: true
MongoException: true

The same occurs with the Mongo class (Mongo.php). I need to rename to AMongo.php to extends from MongoClient

rowillia commented 9 years ago

I have a fix for this in https://github.com/mongofill/mongofill-hhvm/pull/47

ProdigyView commented 9 years ago

I surmise this would fix my issue: https://github.com/mongofill/mongofill-hhvm/issues/45

ezruneko commented 9 years ago

@rowillia perfect solution is more elegant that rename base classes.