-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easier way to return array as default #39
Comments
Thanks for the feedback! We've actually been tracking this in PHPLIB-74 and hope to have it resolved before the 1.0.0 release. Supporting a type map option at the Client, Database, and Collection level is definitely feasible, and we'd also like to provide a class implementing ArrayAccess to use by default (instead of stdClass). We definitely don't want to encourage regular PHP arrays, since those are lossy (we have no way of knowing if |
Thank you, that's great news. The class implementing ArrayAccess would be the perfect transition. Also, I'm not sure if it is a type map feature, but is it possible to allow a custom class for ObjectID to implement the JsonSerializable interface or add a public property to the class ObjectID (it used to be $id in the old driver) so the json_encode function does not return an empty object. |
@vlechemin You can use BSON\toJSON() for that $oid = new MongoDB\BSON\ObjectID();
$bson = MongoDB\BSON\fromPHP(array("oid" => $oid));
$json = MongoDB\BSON\toJSON($bson);
var_dump($json);
I thought we had a ticket for going from PHP to (e)JSON but I cannot find it at the moment. Its not going to make it into 1.0.0 though |
Thanks for the temporary solution and the ticket, I will be waiting for 1.1 |
On a related note, 1.0.0-beta2 of the library includes a new top-level |
I'm trying to use this library in a project who uses the old driver.
But now the default behavior is to return objects from queries.
The only way I found was to make a wrapper around Collection and to specify for each operation (find, findOne, aggregate...) the type map.
Is there a better way to do this? Do you plan having default options for this kind of use case? (inherit from database/client, similar to read preference)
Thanks!
The text was updated successfully, but these errors were encountered: