[wp-trac] [WordPress Trac] #62314: Infinite callback loop when 'priority' is not numeric in php 8.x
WordPress Trac
noreply at wordpress.org
Mon Oct 28 19:35:11 UTC 2024
#62314: Infinite callback loop when 'priority' is not numeric in php 8.x
-------------------------------+-------------------------------
Reporter: mzou23 | Owner: (none)
Type: enhancement | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 6.6.2
Severity: minor | Keywords: changes-requested
Focuses: php-compatibility |
-------------------------------+-------------------------------
The behavior of min(array) has changed in php 8.x. Prior to php 8,
{{{ min(array('a', 1,2,3)) }}} returns 'a'. In php 8.x, it returns 1.
This has some unexpected effects on wordpress filters. The following code
{{{
function test_action() { add_action( 'admin_enqueue_scripts',
function(){}, 'a');}
add_action( 'admin_enqueue_scripts', 'test_action' , 10);
}}}
which works on php 7, will result in an infinite loop on php 8.x.
Strictly speaking, this is not a bug, as using 'a' instead of a numeric
value for priority is incorrect. However, wordpress does not complain its
use.
Here is a simple fix. Add a check in wp-includes/class-wp-hook.php, on
line 83. Either change the priority to a numeric value or barf and bail
out. I think something like
{{{
if( ! is_numeric($priority) ) $priority = 10;
}}}
will be safe.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62314>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list