Make WordPress Core

#60235 closed enhancement (duplicate)

call_user_func_array invalid callback error severity change in PHP 8

Reported by: davidbinda's profile david.binda Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

While testing the PHP 8.x on WordPress.com, PHP fatal errors for invalid callbacks to filters and actions were noticed.

When running WordPress on the PHP 7.x, an invalid callback to a filter/action produces a warning and thus does not stop the script execution. Upgrading to PHP 8.x leads to a fatal error in the same situation.

I wonder whether there should be a is_callable check in the WP_Hook::apply_filters preventing fatal error from happening (plus some _doing_it_wrong notice), as it would make the transition from PHP 7.x to 8.x easier in cases where the error severity change applies.

To replicate the issue should be as easy as adding following to a mu-plugin:

<?php
add_action( 'init', 'non_existing_function' );

Produces warning in PHP 7.x:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'non_existing_function' not found or invalid function name in wp-includes/class-wp-hook.php on line 324

and fatal error in PHP 8.x:

Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "non_existing_function" not found or invalid function name in wp-includes/class-wp-hook.php:324

Change History (1)

#1 @johnbillion
11 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the report David, I'll close this as a duplicate of #51894 and #38116. There are good discussions on both of those tickets.

Note: See TracTickets for help on using tickets.