Skip to content
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

Guard against php8.0 ArgumentCountError #682

Merged
merged 1 commit into from
Dec 14, 2022

Conversation

engahmeds3ed
Copy link
Contributor

Fixes the following error:

2022-06-21T00:00:13+00:00 CRITICAL Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in /home/XXX/public_html/wp-content/plugins/imagify/inc/classes/class-imagify-custom-folders.php:847

that's php8.0 new feature which called Named Parameters which means that we can pass arguments to any function and give them names, something like:

//PHP function usage
function str_contains(string $haystack, string $needle): bool {}

//how to use it with the new feature (named parameters)
str_contains(haystack: 'FooBar', needle: 'Foo');

back to our code, in the following line:

$files_from_db = call_user_func_array( 'array_merge', $files_from_db );

this variable $files_from_db is associative array (array with keys and values) and we are trying to merge all values (which are arrays)
This is because call_user_func_array will interpret the top-level array keys as parameter names to be passed into the array_merge, and these keys will not match the function arguments.
the solution here is just to get the array_values before passing it to call_user_func_array to be like

$files_from_db = call_user_func_array( 'array_merge', array_values( $files_from_db ) );

I wasn't able to see that in the test environment but this PR should fix this error.

@engahmeds3ed engahmeds3ed self-assigned this Aug 6, 2022
@remyperona remyperona added this to the 2.1 milestone Aug 10, 2022
@remyperona remyperona modified the milestones: 2.1, 2.1.1 Nov 7, 2022
@remyperona remyperona merged commit 5295516 into develop Dec 14, 2022
@remyperona remyperona deleted the fix/php8-ArgumentCountError branch December 14, 2022 14:21
@remyperona remyperona mentioned this pull request Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants