-
Notifications
You must be signed in to change notification settings - Fork 210
PHPC-408: Ensure object_to_bson() always creates a BSON document #102
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really wasn't intentional.
I would remove this check from the test, and make a totally new testcase for the exact ticket.
I don't think this is a good idea. Silently serializing objects as empty? I would rather see an exception thrown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make a whole lot of sense to me.
php -r '$d = new DateTime("now"); var_dump($d);' <<<
object(DateTime)#1 (3) {
["date"]=>
string(26) "2015-09-09 16:13:49.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(19) "America/Los_Angeles"
}
Why wouldn't at least the public properties be serialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output is in fact right. It serializes the object's real properties, of which DateTime has none. This is also the output that matches what Hippo does. DateTime only creates those when you make a var_dump() or use the debug handler.... (yes, that is odd).
I don't think however think it's nice to serialize as some random object... hence PHPC-410 makes sense (and #103)
As @derickr mentioned, #103 is my proposed change for that. I just broke these into separate PRs to address the issue Derick raised in PHPC-408 independently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you were going to throw an exception in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/mongodb-labs/mongo-php-driver-prototype/pull/103/files#diff-f7d29a680148f52d6601f59ed787f577R712 throws an exception for an unsupported BSON Type, but any other object will ideally get its public properties serialized.
https://jira.mongodb.org/browse/PHPC-408