Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-431

Segfault when using Manager through singleton class

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.1.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      PHP7.0.0-RC3, Debian 8.1

      When the Manager object is used and passed to other classes (e.g. when wrapped in a Singleton class, or the class that created the object is passed as $this), a SIGSEGV will happen in PHP.

      Repro case:

      <?php
      
      use MongoDB\Driver\Manager;
      use MongoDB\Driver\Query;
      use MongoDB\Driver\ReadPreference;
      
      class Database {
          private $Database;
          private static $Instance;
      
          public function __construct() {
              $Manager = new Manager("mongodb://localhost:27017", array(), array());
              $this->Database = $Manager;
          }
      
          public static function getInstance() {
              if (static::$Instance == null) {
                  static::$Instance = new Database();
              }
      
              return static::$Instance;
          }
      
          public function query($scheme, $query) {
              return $this->Database->executeQuery($scheme, $query, new ReadPreference(ReadPreference::RP_PRIMARY));
          }
      }
      
      class App {
          public function run() {
              $db = Database::getInstance();
              
              $query = new Query(array());
              $cursor = $db->query("mydb.scheme_info", $query);
      
              foreach ($cursor as $document) {
                  echo $document->value;
              }
      
              $query = new Query(array());
              $cursor = $db->query("mydb.domain", $query);
      
              foreach ($cursor as $document) {
                  echo $document->hostname;
              }
          }
      }
      
      $App = new App();
      $App->run();
      

      I'm also getting the issue if, for example, my App object is passed to another class (using new SomeClass($this)). I can't reproduce it in a separate case, however it does happen in my dev project, but I'd assume both issues are linked.

      I know PHP7 support is low in the list, but it'd be awesome if you can just fix that single issue

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            xplodwild xplodwild
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: