-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-1070 and PHPC-1071: Report class name for unexpected object values #705
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
); | ||
zval_ptr_dtor(&obj_data); | ||
#else | ||
if (Z_TYPE_P(obj_data) != IS_ARRAY && !(Z_TYPE_P(obj_data) == IS_OBJECT && instanceof_function(Z_OBJCE_P(obj_data), zend_standard_class_def TSRMLS_CC))) { | ||
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, | ||
"Expected %s::%s() to return an array or stdClass, %s given", | ||
Z_OBJCE_P(object)->name, | ||
ZSTR_VAL(Z_OBJCE_P(object)->name), |
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.
Technically, this isn't necessary since we're in PHP 5 mode here, but it reduces some variation between the PHP 5 and 7 blocks. The only real difference in these blocks is that obj_data
is a zval *
for PHP 5.
#else | ||
Z_OBJCE_P(data)->name, | ||
#endif | ||
ZSTR_VAL(Z_OBJCE_P(data)->name), |
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.
We could have eliminated the #if
block much earlier, but I just noticed this.
(Z_TYPE_P(obj_data) == IS_OBJECT | ||
? Z_OBJCE_P(obj_data)->name | ||
: zend_get_type_by_const(Z_TYPE_P(obj_data)) | ||
PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(obj_data) |
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.
Only difference here is that obj_data
is a zval *
for PHP 5.
This only updates exceptions where object types are entirely unexpected. For instance, options that expect a BSON document (i.e. array or object) need not use this macro, as any object would be accepted.
https://jira.mongodb.org/browse/PHPC-1070
https://jira.mongodb.org/browse/PHPC-1071
Adds a macro for accessing zval's class or type name, depending on whether it's an object type. This replaces existing ternary statements we had for some BSON exceptions. I've also gone through and updated exceptions where object types are entirely unexpected. Options that expect a BSON document (i.e. array or object) remain unchanged and do not use this macro, as any object type would be accepted.
IMO, this makes the exceptions more helpful and also makes PHPC more consistent with the invalid type exception messages in PHPLIB.