note 105860 added to mongocollection.find

From: Date: Tue, 20 Sep 2011 14:48:43 +0000
Subject: note 105860 added to mongocollection.find
Groups: php.notes 
Request: Send a blank email to php-notes+get-183307@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: $fields = new stdClass; $fields->{123} = 0; $fields->{321} = 0; ---- Server IP: 69.147.83.197 Probable Submitter: 92.42.150.58 ---- Manual Page -- http://www.php.net/manual/en/mongocollection.find.php Edit -- https://master.php.net/note/edit/105860 Del: integrated -- https://master.php.net/note/delete/105860/integrated Del: useless -- https://master.php.net/note/delete/105860/useless Del: bad code -- https://master.php.net/note/delete/105860/bad+code Del: spam -- https://master.php.net/note/delete/105860/spam Del: non-english -- https://master.php.net/note/delete/105860/non-english Del: in docs -- https://master.php.net/note/delete/105860/in+docs Del: other reasons-- https://master.php.net/note/delete/105860 Reject -- https://master.php.net/note/reject/105860 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183307) next »