|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63333 PHP should return documents as objects, not arrays.
Submitted: 2012-10-22 15:00 UTC Modified: 2012-11-29 16:20 UTC
From: dtrenz at gmail dot com Assigned:
Status: Wont fix Package: mongo (PECL)
PHP Version: 5.3.18 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dtrenz at gmail dot com
New email:
PHP Version: OS:


 [2012-10-22 15:00 UTC] dtrenz at gmail dot com
When querying as MongoDB collection, the Mongo PHP module returns document 
objects as arrays, not as objects.

Mongo is comprised of collections of BSON objects, which should be stored & 
retrieved as objects, not as arrays.

Even the tutorial ( refers to 
these arrays as "objects" or "$obj", which is puzzling.

Test script:

$m = new Mongo();

$collection = $m->test->users;

$collection->insert(array('name' => 'John Doe'));

$cursor = $m->test->users->findOne();



Expected result:
stdClass Object
    [_id] => MongoId Object
            [$id] => 50818a58d0d2ac397739d963

    [name] => John Doe

Actual result:
    [_id] => MongoId Object
            [$id] => 50818a58d0d2ac397739d963

    [name] => John Doe


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-29 16:20 UTC]
Automatic comment from SVN on behalf of derick
Log: Bug #63333: %s/$obj/$document
 [2012-11-29 16:20 UTC]
-Status: Open +Status: Wont fix
 [2012-11-29 16:20 UTC]
We can't ever change this. It would break all scripts reading data from MongoDB here. I have change the tutorial to use $document instead of $obj though (which will show up when the docs get rebuild next).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 23:01:28 2024 UTC