note 105860 modified in mongocollection.find by danbrown
| From: | danbrown@php.net | Date: | Tue, 20 Sep 2011 14:52:03 +0000 |
| Subject: | note 105860 modified in mongocollection.find by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183308@lists.php.net to get a copy of this message | ||
An undocumented feature is that you can pass a stdClass instead of an array to $fields which will
allow you to get around the issue of PHP casting string values to integers which mongo doesn't
like. i.e.
array('123' => 0, '321' => 0);
becomes:
array(213 => 0, 312 => 0);
which will trip up with the error:
PHP Fatal error: Uncaught exception 'MongoException' with message 'field names must
be strings'
The fix is as simple as:
<?php
$fields = new stdClass;
$fields->{123} = 0;
$fields->{321} = 0;
?>
--was--
An undocumented feature is that you can pass a stdClass instead of an array to $fields which will
allow you to get around the issue of PHP casting string values to integers which mongo doesn't
like. i.e.
array('123' => 0, '321' => 0);
becomes:
array(213 => 0, 312 => 0);
which will trip up with the error:
PHP Fatal error: Uncaught exception 'MongoException' with message 'field names must
be strings'
The fix is as simple as:
$fields = new stdClass;
$fields->{123} = 0;
$fields->{321} = 0;
http://php.net/manual/en/mongocollection.find.php