Many feed types fail to generate on PHP8
-
While iterating over various feed types, I noticed that some of them fail to be generated. For example, the “Shopping” feed fails, and the following stack trace is logged into wordpress debug log if logging is enabled:
0 …/public_html/wp-content/plugins/woocommerce-feed-manager/admin/feed/class-rex-product-feed-shopping.php(177): array_merge()
1 …/public_html/wp-content/plugins/woocommerce-feed-manager/admin/feed/class-rex-product-feed-shopping.php(121): Rex_Product_Feed_Shopping->add_to_feed()
2 …/public_html/wp-content/plugins/woocommerce-feed-manager/admin/feed/class-rex-product-feed-shopping.php(28): Rex_Product_Feed_Shopping->generate_product_feed()
3 …/public_html/wp-content/plugins/woocommerce-feed-manager/admin/class-rex-product-feed-ajax.php(296): Rex_Product_Feed_Shopping->make_feed()
4 [internal function]: Rex_Product_Feed_Ajax::generate_feed()
5 …/public_html/wp-content/plugins/woocommerce-feed-manager/vendor/philipnewcomer/wp-ajax-helper/src/components/Utility.php(89): call_user_func_array()
6 …/public_html/wp-content/plugins/woocommerce-feed-manager/vendor/philipnewcomer/wp-ajax-helper/src/components/Utility.php(57): PhilipNewcomer\WP_Ajax_Helper\Utility::run_callback()
7 …/public_html/wp-content/plugins/woocommerce-feed-manager/vendor/philipnewcomer/wp-ajax-helper/src/components/Handler.php(109): PhilipNewcomer\WP_Ajax_Helper\Utility::get_callback_response()
8 …/public_html/wp-includes/class-wp-hook.php(324): PhilipNewcomer\WP_Ajax_Helper\Handler->ajax_handler()
9 …/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
10 …/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
11 …/public_html/wp-admin/admin-ajax.php(192): do_action() 12 {main}The error happens in this line:
$value = call_user_func_array('array_merge', $value);. I’ve debugged the problem and it boils down to a change in how PHP8 treats the keys of the second argument tocall_user_func_array(): while previously keys were simply ignored, in PHP8, they are treated as names for the newly introduced named arguments.A workaround for this would be to use
array_values($value)as second argument.Another possible option is to replace this hacky-looking call, which something cleaner. I don’t know if that’s indeed the case, but if this call was designed to simply remove the outer level of a potentially multi-level array (as I suspect is the case), a simple call to
current()orreset()could be used to achieve that same effect, would look much cleaner, and would not trigger the error above.EDIT: both
current()andreset()will returnfalseif the array is empty, so for the next line (implode()) to work, you should cover such case as well. For example:$value = reset($value) ?: [];.
The topic ‘Many feed types fail to generate on PHP8’ is closed to new replies.