[wp-trac] [WordPress Trac] #53635: PHP 8.1: various compatibility fixes

WordPress Trac noreply at wordpress.org
Mon Aug 16 15:22:53 UTC 2021


#53635: PHP 8.1: various compatibility fixes
--------------------------------------------+------------------------------
 Reporter:  SergeyBiryukov                  |       Owner:  hellofromTonya
     Type:  task (blessed)                  |      Status:  accepted
 Priority:  normal                          |   Milestone:  5.9
Component:  General                         |     Version:
 Severity:  normal                          |  Resolution:
 Keywords:  php81 has-patch has-unit-tests  |     Focuses:  coding-
                                            |  standards
--------------------------------------------+------------------------------

Comment (by SergeyBiryukov):

 In [changeset:"51619" 51619]:
 {{{
 #!CommitTicketReference repository="" revision="51619"
 Code Modernization: Check the return type of `_get_cron_array()` in
 `wp_schedule_event()`.

 This fixes a "Deprecated: Automatic conversion of false to array is
 deprecated" warning on PHP 8.1.

 In `wp_schedule_event()`, the cron info array is retrieved via a call to
 `_get_cron_array()`, but as the documentation (correctly) states, the
 return type of that function is `array|false`, where `false` is returned
 for a virgin site, with no cron jobs scheduled yet.

 However, no type check is done on the return value, and the
 `wp_schedule_event()` function just blindly continues by assigning a value
 to a subkey of the `$crons` "array".

 Fixed by adding validation for the returned value from `_get_cron_array()`
 and initializing an empty array if `false` was returned.

 Reference:
 [https://developer.wordpress.org/reference/functions/_get_cron_array/
 WordPress Developer Resources: _get_cron_array()]

 Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca,
 SergeyBiryukov.
 See #53635.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53635#comment:34>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list