diff options
author | George Peter Banyard <girgias@php.net> | 2020-05-03 00:35:13 +0200 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2020-05-06 21:51:59 +0200 |
commit | 038502b92a1009fa83aa60602b20446e698e7437 (patch) | |
tree | 587e3cac675f1773cc06b81980a16114272a2d9e /ext/reflection/php_reflection.c | |
parent | b63eff17ffcc1041fed752a0ea7902759329af63 (diff) | |
download | php-git-038502b92a1009fa83aa60602b20446e698e7437.tar.gz |
Use int|string Fast ZPP macro in Reflection
Moreover, throw a more appropriate ValueError in case the integer
position provided is less than 0.
Closes GH-5513
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 2856e0c6db..1ed057d902 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2112,20 +2112,22 @@ ZEND_METHOD(ReflectionGenerator, getExecutingGenerator) ZEND_METHOD(ReflectionParameter, __construct) { parameter_reference *ref; - zval *reference, *parameter; + zval *reference; + zend_string *arg_name = NULL; + zend_long position; zval *object; zval *prop_name; reflection_object *intern; zend_function *fptr; struct _zend_arg_info *arg_info; - int position; uint32_t num_args; zend_class_entry *ce = NULL; zend_bool is_closure = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &reference, ¶meter) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(reference) + Z_PARAM_STR_OR_LONG(arg_name, position) + ZEND_PARSE_PARAMETERS_END(); object = ZEND_THIS; intern = Z_REFLECTION_P(object); @@ -2223,34 +2225,23 @@ ZEND_METHOD(ReflectionParameter, __construct) if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } - if (Z_TYPE_P(parameter) == IS_LONG) { - position= (int)Z_LVAL_P(parameter); - if (position < 0 || (uint32_t)position >= num_args) { - _DO_THROW("The parameter specified by its offset could not be found"); - goto failure; - } - } else { + if (arg_name != NULL) { uint32_t i; - position = -1; - if (!try_convert_to_string(parameter)) { - goto failure; - } if (has_internal_arg_info(fptr)) { for (i = 0; i < num_args; i++) { if (arg_info[i].name) { - if (strcmp(((zend_internal_arg_info*)arg_info)[i].name, Z_STRVAL_P(parameter)) == 0) { + if (strcmp(((zend_internal_arg_info*)arg_info)[i].name, ZSTR_VAL(arg_name)) == 0) { position = i; break; } - } } } else { for (i = 0; i < num_args; i++) { if (arg_info[i].name) { - if (strcmp(ZSTR_VAL(arg_info[i].name), Z_STRVAL_P(parameter)) == 0) { + if (zend_string_equals(arg_name, arg_info[i].name)) { position = i; break; } @@ -2261,6 +2252,15 @@ ZEND_METHOD(ReflectionParameter, __construct) _DO_THROW("The parameter specified by its name could not be found"); goto failure; } + } else { + if (position < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + goto failure; + } + if (position >= num_args) { + _DO_THROW("The parameter specified by its offset could not be found"); + goto failure; + } } ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); @@ -2292,6 +2292,7 @@ failure: if (is_closure) { zval_ptr_dtor(reference); } + RETURN_THROWS(); } /* }}} */ |