[wp-trac] [WordPress Trac] #53940: Reconsider return types for `_get_cron_array()`.
WordPress Trac
noreply at wordpress.org
Tue Aug 17 01:58:09 UTC 2021
#53940: Reconsider return types for `_get_cron_array()`.
---------------------------+------------------------------------------
Reporter: peterwilsoncc | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version:
Severity: normal | Keywords: needs-patch needs-unit-tests
Focuses: |
---------------------------+------------------------------------------
[https://core.trac.wordpress.org/browser/tags/5.8/src/wp-
includes/cron.php?marks=1154-1175#L1154 `_get_cron_array()`] currently has
multiple return types:
* `false`: The `cron` option is not set/is set incorrectly
* `array`: The `cron` option is set correctly and either does or does not
contain any cron jobs.
As either type can be returned when there are no cron jobs, I think it's
worth discussing whether the return types are correct, specifically:
* should the function always return an `array`
* should the function always return `false` when there are zero cron jobs
Either change would improve the consistency of the return type but be a
technical break of backward compatibility.
My inclination is to always return an `array` as it's fair to expect
`delete_option( '_cron' )` zeros out the cron jobs in the same way that
`_set_cron_array( [] )` does.
I also think always returning an array when there is no option/no cron
jobs is more consistent than returning a different type when there are
zero registered jobs depending on how they were deleted.
Follow up to #3058, #53635.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53940>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list