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

MongoDB\BSON\toPHP() is rewriting $typeMap argument

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.2
    • Affects Version/s: 1.5.0
    • Component/s: None
    • None
    • Environment:
      Debian Buster

      Hello, first I apologize if this issue has already been addressed.

      I am using Doctrine ODM on Debian Buster (so it's php-mongodb 1.5.3-2 ). And I had a problem when executing some findAndUpdate request :

       

      $qb = $this->createQueryBuilder()
       ->findAndUpdate()
       ->returnNew()
       ->field('expires')
       ->lte(new DateTimeImmutable())
       ->field('status')
       ->set(Status::LOCKED())
       // other stuff
       ->getQuery()
       ->execute();

      After that request, any other request to database ended up with this exception :

       

      MongoDB\\Driver\\Exception\\InvalidArgumentException(code: 0): Class \u0001 does not exist

       

      After digging I realize the property typeMap of MongoDB\Client class changes everytime the {{apply_type_map_to_document()}} function is called. To fix this problem I had to modify this function in order to pass a $typeMap array that is not used anywhere to \MongoDB\BSON\toPHP():

       

      function apply_type_map_to_document($document, array $typeMap)
      {
          if ( ! is_array($document) && ! is_object($document)) {
              throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
          }
          $tm=[];
          foreach($typeMap as $k=>$v){
              $tm[$k]=$v;
          }
          return \MongoDB\BSON\toPHP(\MongoDB\BSON\fromPHP($document), $tm);
      }
      

      Thank you for your time.

       

      PS : I already describe the problem in this Stack overflow question/answer

       

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            mongo@n00dl3.ovh Bob D
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: