Opened 4 years ago
Closed 4 years ago
#51900 closed enhancement (duplicate)
[PHP 8] Named parameters in hook `call_user_func_array()` calls
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | php8 close |
Focuses: | Cc: |
Description
PHP 8.0 is here, and it comes with named parameters.
While named parameter is a new feature that syntax would simply not work in older PHP versions, `call_user_func_array function behaves differently.
WordPress uses call_user_func_array
extensively throughout the code, including filters and actions. With PHP 8.0, if the second parameter ($param_arr
) is an associative array, PHP tries to call the callable as a named parameter.
See example: https://3v4l.org/RhjrU
What this means for WordPress, is that all parameters that a registered action, filter, or a standard "params" value must not be an associative array. This behavior is not warned. If the parameter array keys match function parameters, that is mostly a safe call, but if there is at least one parameter name that does not match, PHP will then raise a fatal error.
One easy way to "normalize" the parameters is to call array_values
before calling the function.
Before submitting any patches, I would like to request opinions if this is desirable for WordPress. I guess reports will come in once users start to use PHP 8.0, and it's probably an easier fix at call_user_func_array()
call-site rather than the action/filter/params declaration.
Disclosure: I am the author of the page linked at the top of this ticket; I believe it provides more context without typing the whole story.
Change History (4)
#1
@
4 years ago
- Summary changed from [PHP 8] Named paramters in hook `call_user_func_array()` calls to [PHP 8] Named parameters in hook `call_user_func_array()` calls
Duplicate of task 3 of ticket #51553