[wp-trac] [WordPress Trac] #64404: Uncaught DivisionByZeroError: Modulo by zero

WordPress Trac noreply at wordpress.org
Tue Feb 24 16:00:05 UTC 2026


#64404: Uncaught DivisionByZeroError: Modulo by zero
----------------------------+--------------------------
 Reporter:  kaushiksomaiya  |       Owner:  westonruter
     Type:  defect (bug)    |      Status:  accepted
 Priority:  normal          |   Milestone:  7.0
Component:  Cron API        |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+--------------------------

Comment (by huzaifaalmesbah):

 == Test Report ==

 Patch Tested: [https://github.com/WordPress/wordpress-develop/pull/10619
 PR #10619]

 === Environment
 - WordPress: 7.0-beta1-61709-src
 - PHP: 8.2.29
 - Server: nginx/1.29.5
 - Database: mysqli (Server: 8.4.8 / Client: mysqlnd 8.2.29)
 - Browser: Chrome 145.0.0.0
 - OS: macOS
 - Theme: Twenty Eleven 5.0
 - MU Plugins:
   * test-64404.php
 - Plugins:
   * Test Reports 1.2.1

 === Steps taken
  1. Create a file named `test-64404.php` in the `/wp-content/mu-plugins/`
 directory.
  2. Paste the provided **MU Plugin Code** from the ''Support Content''
 section below into the file. This code intentionally registers a broken
 cron schedule (`'interval' => false`).
  3. Run the following WP-CLI command to trigger the `init` action and
 properly schedule the broken cron event:
 {{{
 wp eval 'echo "init triggered";'
 }}}
  4. List the scheduled events to verify the broken hook is in the queue:
 {{{
 wp cron event list
 }}}
  5. '''Testing `trunk` (Before Patch):''' While on `trunk`, run the broken
 cron event manually:
 {{{
 wp cron event run kscronbreaker_broken_cron_hook
 }}}
  6. The process crashes and a fatal `DivisionByZeroError` is returned:
 {{{
 Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /var/www/src
 /wp-includes/cron.php:463
 Stack trace:
 #0 phar:///usr/local/bin/wp/vendor/wp-cli/cron-
 command/src/Cron_Event_Command.php(352): wp_reschedule_event(1771947435,
 'kscronbreaker_c...', 'kscronbreaker_b...', Array)
 #1 phar:///usr/local/bin/wp/vendor/wp-cli/cron-
 command/src/Cron_Event_Command.php(238):
 Cron_Event_Command::run_event(Object(stdClass))
 ...
 Error: There has been a critical error on this website.
 }}}
  7. '''Testing [https://github.com/WordPress/wordpress-develop/pull/10619
 PR #10619] (After Patch):''' Apply the patch from PR 10619.
  8. Run the exact same WP-CLI command to execute the broken event:
 {{{
 wp cron event run kscronbreaker_broken_cron_hook
 }}}
  9. The event gracefully skips rescheduling itself without crashing PHP.
 The command successfully finishes executing:
 {{{
 Executed the cron event 'kscronbreaker_broken_cron_hook' in 0.04s.
 Success: Executed a total of 1 cron event.
 }}}
  10. ✅ **Patch is solving the problem / works as expected**

 === Expected Results ===
 When a scheduled cron event has an invalid interval (such as a boolean
 `false` instead of an integer), the system should gracefully fail to
 reschedule the event. It should not cause a fatal `DivisionByZeroError`
 that breaks the entire cron execution process.

 === Additional Notes ===
 * The patch effectively guards against division/modulo by zero by
 validating that the interval is functionally greater than 0 before
 performing the calculation.

 === Support Content ===

 '''1. MU Plugin Code (`wp-content/mu-plugins/test-64404.php`)'''
 {{{#!php
 <?php
 // 1. Add a broken schedule
 add_filter( 'cron_schedules', function( $schedules ) {
         // INTENTIONALLY BROKEN
         $schedules['kscronbreaker_cron_schedule'] = array(
                 'interval' => false, // ❌ Wrong: must be integer > 0
                 'display'  => 'Broken Cron Schedule',
         );
         return $schedules;
 } );

 // 2. Try to schedule the event
 add_action( 'init', function() {
         if ( ! wp_next_scheduled( 'kscronbreaker_broken_cron_hook' ) ) {
                 wp_schedule_event( time() + 10,
 'kscronbreaker_cron_schedule', 'kscronbreaker_broken_cron_hook' );
         }
 } );

 // 3. Cron handler (never runs on trunk)
 add_action( 'kscronbreaker_broken_cron_hook', function() {
         error_log( 'KS Cron Breaker executed!' );
 } );
 }}}

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


More information about the wp-trac mailing list