php.net |  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
 [2012-10-22 15:00 UTC] dtrenz at gmail dot com
Description:
------------
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 (http://www.php.net/manual/en/mongo.tutorial.php) refers to 
these arrays as "objects" or "$obj", which is puzzling.

Test script:
---------------
<?php

$m = new Mongo();

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

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

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

var_dump($cursor);

?>

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

    [name] => John Doe
)

Actual result:
--------------
Array
(
    [_id] => MongoId Object
        (
            [$id] => 50818a58d0d2ac397739d963
        )

    [name] => John Doe
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-29 16:20 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328572
Log: Bug #63333: %s/$obj/$document
 [2012-11-29 16:20 UTC] derick@php.net
-Status: Open +Status: Wont fix
 [2012-11-29 16:20 UTC] derick@php.net
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 Dec 21 12:01:31 2024 UTC