[wp-trac] [WordPress Trac] #60235: call_user_func_array invalid callback error severity change in PHP 8
WordPress Trac
noreply at wordpress.org
Thu Jan 11 15:50:21 UTC 2024
#60235: call_user_func_array invalid callback error severity change in PHP 8
-------------------------+-----------------------------
Reporter: david.binda | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
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
<?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`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60235>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list