[php-src] Issue #10341: Adding hasParameter() and getParameter() methods to ReflectionFunctionAbstract

From: Date: Mon, 16 Jan 2023 14:33:24 +0000
Subject: [php-src] Issue #10341: Adding hasParameter() and getParameter() methods to ReflectionFunctionAbstract
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243462@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10341 Author: ollieread ### Description We currently have getMethod() and getProperty() methods to retrieve a single method or properly by its name, but we do not have the same for parameters, even though we now have named properties. I am happy to PR this, and I _think_ I may have figured out a way to achieve it, but right now, it involves looping through the parameters until one that matches is found, which feels less than ideal. Here's ReflectionFunctionAbstract::hasParameter() ```c /* {{{ Returns whether a parameter exists or not */ ZEND_METHOD(ReflectionFunctionAbstract, hasParameter) { reflection_object *intern; zend_function *fptr; struct _zend_arg_info *arg_info; zend_string *name, *lc_name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { RETURN_THROWS(); } if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } GET_REFLECTION_OBJECT_PTR(fptr); arg_info= fptr->common.arg_info; num_args = fptr->common.num_args; if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } if (!num_args) { RETURN_FALSE; } lc_name = zend_string_tolower(name); for (i = 0; i < num_args; i++) { zval parameter; reflection_parameter_factory( _copy_function(fptr), Z_ISUNDEF(intern->obj) ? NULL : &intern->obj, arg_info, i, i < fptr->common.required_num_args, &parameter ); if (arg_info.name == lc_name) { RETURN_TRUE; } arg_info++; } zend_string_release(lc_name); RETURN_FALSE; } /* }}} */ ``` I think, if I can figure out (or pointed towards) how to return parameter, I could use the same code for ReflectionFunctionAbstract::getParameter(). Would appreciate any feedback on the proposal and also pointers for the code.

« previous php.bugs (#243462) next »