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

BSON encoding should throw on circular references

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2.9
    • Affects Version/s: 1.2.8
    • Component/s: None
    • Labels:
      None

      The following segfaults for BSON encoding:

      class MyIndirectlyRecursiveWrapper implements MongoDB\BSON\Serializable
      {
          public $x => 1;
      
          public function bsonSerialize()
          {
              return ['x' => $this];
          }
      }
      

      The more direct example, where bsonSerialize() returns $this, is caught due to an earlier check that the return value is an array or stdClass.

      On a related note, bson-fromPHP-004.phpt currently has tests for circular references in PHP arrays and generic objects, which result in the circular reference being ignored with no error. We should be throwing an exception instead of silently ignoring recursion.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: