-
Notifications
You must be signed in to change notification settings - Fork 208
->[to|from]Array() -> [to|from]PHP(). "root" typemapping. Default "root" to stdclass, not array #56
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
e250088
to
2ad506f
Compare
@@ -73,7 +73,7 @@ object(MongoDB\Driver\Cursor)#%d (%d) { | |||
["mode"]=> | |||
int(1) | |||
["tags"]=> | |||
array(0) { | |||
object(stdClass)#%d (0) { |
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.
@bjori: When mongoc_read_prefs_t
is initialized, its tags are also initialized to an empty BSON document. In turn, php_phongo_read_preference_to_zval()
will do:
if (read_prefs->tags.len) {
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
MAKE_STD_ZVAL(state.zchild);
bson_to_zval(bson_get_data(&read_prefs->tags), read_prefs->tags.len, &state);
add_assoc_zval_ex(retval, ZEND_STRS("tags"), state.zchild);
} else {
add_assoc_null_ex(retval, ZEND_STRS("tags"));
}
That else
condition will really never be reached. Would you rather I change the condition to read_prefs->tags.len > 5
and add a comment that we only dump it if it's a non-empty document? Otherwise, I can leave this as-is.
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 think all the else append null checks were all added at the same time (dozens of them) after I realized not everything was initialized everytime, so var_dump()ing had the tendency to crash.
I don't think I ever checked individual cases, but instead always added a fallback path.
I'd say in this particular case, tags = null would look weird. tags = array() looks best.
Why is this stdClass now? that looks weird?
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.
Why is this stdClass now? that looks weird?
I'm changing php_phongo_read_preference_to_zval()
, Server::getTags()
, Server::getInfo()
, and php_phongo_server_to_zval()
to use native array decoding, as we discussed earlier.
4dd8f9e
to
3d04657
Compare
* | ||
* TODO: decide if native array/object should be allowed to override this, | ||
* in which case we only supersede PHONGO_TYPEMAP_NONE. | ||
*/ |
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.
no code todo please. They are destined to rot.
If its realistic, add a ticket. If not. swallow it :]
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.
Created PHPC-329, so I'll remove this.
I've fixed the failing test on travis and am kicking the builds now |
06ca6a8
to
7df7934
Compare
Update tests to expect stdClass for documents. Debug handlers and the Server getter methods will still decode documents as native arrays.
@bjori: I cleaned up the cases where I replaced |
@@ -957,7 +979,7 @@ void php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *ma | |||
map->array_type = PHONGO_TYPEMAP_NATIVE_OBJECT; | |||
} else { | |||
map->array_type = PHONGO_TYPEMAP_CLASS; | |||
array_ce = zend_fetch_class(classname, classname_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); | |||
zend_class_entry *array_ce = zend_fetch_class(classname, classname_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); |
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.
Variable declarations need to be done first.
This won't compile on VS.. And I thought this was part of our --enable-developer-flags (-Wdeclaration-after-statement).
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.
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.
Good catch. I surely must have missed this stderr output when building locally.
LGTM
|
Rebased the PHPC-315 commit to fix the build warnings, and also adjusted my build scripts to I should catch stderr output more easily in the future. I left an explanation of why I changed the |
oklgtm |
Rename BSON\to|from]Array() to BSON[to|from]PHP()
Support setting the "root" (container) value to explicit type.
->setTypemap(["root" => "array"]);
Use stdClass, not array, for top-level containers by default