-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add more accurate types to stubs again #6068
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1221,8 +1221,8 @@ static zend_always_inline zval *zend_try_array_init(zval *zv) | |
_(Z_EXPECTED_DOUBLE_OR_NULL, "of type ?float") \ | ||
_(Z_EXPECTED_NUMBER, "of type int|float") \ | ||
_(Z_EXPECTED_NUMBER_OR_NULL, "of type int|float|null") \ | ||
_(Z_EXPECTED_STRING_OR_ARRAY, "of type string|array") \ | ||
_(Z_EXPECTED_STRING_OR_ARRAY_OR_NULL, "of type string|array|null") \ | ||
_(Z_EXPECTED_STRING_OR_ARRAY, "of type array|string") \ | ||
_(Z_EXPECTED_STRING_OR_ARRAY_OR_NULL, "of type array|string|null") \ | ||
_(Z_EXPECTED_STRING_OR_LONG, "of type string|int") \ | ||
_(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \ | ||
_(Z_EXPECTED_CLASS_NAME_OR_OBJECT, "a valid class name or object") \ | ||
|
@@ -1511,6 +1511,9 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char * | |
#define Z_PARAM_ARRAY_HT(dest) \ | ||
Z_PARAM_ARRAY_HT_EX(dest, 0, 0) | ||
|
||
#define Z_PARAM_ARRAY_HT_OR_NULL(dest) \ | ||
Z_PARAM_ARRAY_HT_EX(dest, 1, 0) | ||
|
||
/* old "H" */ | ||
#define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \ | ||
Z_PARAM_PROLOGUE(deref, separate); \ | ||
|
@@ -1577,6 +1580,23 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char * | |
#define Z_PARAM_OBJECT_OR_NULL(dest) \ | ||
Z_PARAM_OBJECT_EX(dest, 1, 0) | ||
|
||
#define Z_PARAM_OBJ_EX2(dest, check_null, deref, separate) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment above it, so it's obvious what the difference is? |
||
Z_PARAM_PROLOGUE(deref, separate); \ | ||
if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \ | ||
_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \ | ||
_error_code = ZPP_ERROR_WRONG_ARG; \ | ||
break; \ | ||
} | ||
|
||
#define Z_PARAM_OBJ_EX(dest, check_null, separate) \ | ||
Z_PARAM_OBJ_EX2(dest, check_null, separate, separate) | ||
|
||
#define Z_PARAM_OBJ(dest) \ | ||
Z_PARAM_OBJ_EX(dest, 0, 0) | ||
|
||
#define Z_PARAM_OBJ_OR_NULL(dest) \ | ||
Z_PARAM_OBJ_EX(dest, 1, 0) | ||
|
||
/* old "O" */ | ||
#define Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, deref, separate) \ | ||
Z_PARAM_PROLOGUE(deref, separate); \ | ||
|
@@ -1952,6 +1972,19 @@ static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zen | |
return 1; | ||
} | ||
|
||
static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null) | ||
{ | ||
if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) && | ||
(!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) { | ||
*dest = Z_OBJ_P(arg); | ||
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) { | ||
*dest = NULL; | ||
} else { | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null) | ||
{ | ||
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) { | ||
|
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.
So that we use the canonical form. I'll carve out these changes to a separate commit.