-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Let closure created from magic method accept named parameters #11364
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
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 don't know this code that well but this looks correct to me, thank you!
@@ -841,7 +852,7 @@ void zend_closure_from_frame(zval *return_value, zend_execute_data *call) { /* { | |||
|
|||
memset(&trampoline, 0, sizeof(zend_internal_function)); | |||
trampoline.type = ZEND_INTERNAL_FUNCTION; | |||
trampoline.fn_flags = mptr->common.fn_flags & ZEND_ACC_STATIC; | |||
trampoline.fn_flags = mptr->common.fn_flags & (ZEND_ACC_STATIC | ZEND_ACC_VARIADIC); |
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 just noticed something else, above there is a check for the __invoke
magic method that compares a C string, but we have a known interned string for this ZEND_STR_MAGIC_INVOKE
, wondering if it makes more sense to use this with zend_string_equals()
as it will use a pointer comparison first.
But that is an aside.
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.
Probably, feel free to open a PR and check if there's more such cases ;)
if (EX_CALL_INFO() & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { | ||
zend_string *name; | ||
zval *named_param_zval; | ||
array_init_size(&fci.params[1], ZEND_NUM_ARGS() + zend_hash_num_elements(EX(extra_named_params))); | ||
/* Avoid conversion from packed to mixed later. */ | ||
zend_hash_real_init_mixed(Z_ARRVAL(fci.params[1])); | ||
zend_copy_parameters_array(ZEND_NUM_ARGS(), &fci.params[1]); | ||
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, named_param_zval) { | ||
Z_TRY_ADDREF_P(named_param_zval); | ||
zend_hash_add_new(Z_ARRVAL(fci.params[1]), name, named_param_zval); | ||
} ZEND_HASH_FOREACH_END(); | ||
} else if (ZEND_NUM_ARGS()) { |
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 was wondering why we couldn't use the *named_params
field of the FCI struct, before realising that we need to merge all the parameters into a single array to pass as an argument to the magic method.
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.
This looks right.
Closes GH-11348.